Class: AlTimestamp
Overview
Note:
年月日と時分秒を扱う
タイムスタンプウィジェット
内部的にはTimeオブジェクトで保存する。
Constant Summary collapse
- STRFTIME_FORMAT =
"%Y-%m-%d %H:%M:%S"
Instance Attribute Summary collapse
-
#max ⇒ Integer
最大値.
-
#min ⇒ Integer
最小値.
Attributes inherited from AlWidget
#filter, #foreign, #hidden, #label, #message, #name, #required, #tag_attr, #tag_type, #value, #value_format
Instance Method Summary collapse
-
#initialize(name, arg = {}) ⇒ AlTimestamp
constructor
(AlTimestamp) constructor.
-
#make_tag(appendix_tag = {}) ⇒ String
(AlTimestamp) HTMLタグの生成.
-
#make_value(*arg) ⇒ String
(AlTimestamp) HTML値の生成.
-
#validate ⇒ Boolean
(AlTimestamp) バリデート.
Methods inherited from AlWidget
Constructor Details
#initialize(name, arg = {}) ⇒ AlTimestamp
(AlTimestamp) constructor
1518 1519 1520 1521 1522 1523 1524 1525 |
# File 'lib/al_form.rb', line 1518 def initialize( name, arg = {} ) super( name, arg ) @value_format ||= self.class::STRFTIME_FORMAT @filter = arg[:filter] || AlForm::FILTER_STRIP @max = normalize( arg[:max] ) @min = normalize( arg[:min] ) end |
Instance Attribute Details
#max ⇒ Integer
Returns 最大値.
1503 1504 1505 |
# File 'lib/al_form.rb', line 1503 def max @max end |
#min ⇒ Integer
Returns 最小値.
1506 1507 1508 |
# File 'lib/al_form.rb', line 1506 def min @min end |
Instance Method Details
#make_tag(appendix_tag = {}) ⇒ String
(AlTimestamp) HTMLタグの生成
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 |
# File 'lib/al_form.rb', line 1571 def make_tag( appendix_tag = {} ) if @hidden return %Q(<input type="hidden" name="#{@name}" id="#{@name}" value="#{make_value()}">\n) end r = %Q(<input type="#{@tag_type || "text"}" name="#{@name}" id="#{@name}" value="#{make_value()}") make_tag_attr(r, appendix_tag) r << ">" return r end |
#make_value(*arg) ⇒ String
(AlTimestamp) HTML値の生成
1589 1590 1591 1592 1593 1594 1595 1596 |
# File 'lib/al_form.rb', line 1589 def make_value( *arg ) v = arg.empty? ? @value : arg[0] if v.class == Time return v.strftime( @value_format ) else return Alone::escape_html( v ) end end |
#validate ⇒ Boolean
(AlTimestamp) バリデート
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 |
# File 'lib/al_form.rb', line 1533 def validate() @message = "" if @value == "" || @value == nil if @required @message = p_("al", "%s is required.") % @label return false end @value = nil return true end begin @value = normalize( @value.to_s ) rescue @message = p_("al", "Please enter %s correctly.") % @label return false end if @max && @value > @max @message = p_("al", "%1$s must be no more than %2$s.") % [@label, @max.strftime(@value_format)] return false end if @min && @value < @min @message = p_("al", "%1$s must be at least %2$s.") % [@label, @min.strftime(@value_format)] return false end return true end |