Class: Setsumei::Describable::DateTimeAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/setsumei/describable/date_time_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, format, parser) ⇒ DateTimeAttribute

Returns a new instance of DateTimeAttribute.



5
6
7
8
# File 'lib/setsumei/describable/date_time_attribute.rb', line 5

def initialize type, format, parser
  @type, @parser = type, parser
  @format = format || '%Y-%m-%d %H:%M'
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/setsumei/describable/date_time_attribute.rb', line 9

def format
  @format
end

#parserObject (readonly)

Returns the value of attribute parser.



9
10
11
# File 'lib/setsumei/describable/date_time_attribute.rb', line 9

def parser
  @parser
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/setsumei/describable/date_time_attribute.rb', line 9

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
# File 'lib/setsumei/describable/date_time_attribute.rb', line 11

def == other
  type == other || self.class == other
end

#cast(value) ⇒ Object



15
16
17
# File 'lib/setsumei/describable/date_time_attribute.rb', line 15

def cast value
  parser.strptime value, format
end