Module: Chiketto::AttrDSL::DSL

Defined in:
lib/chiketto/attr_attribute.rb

Instance Method Summary collapse

Instance Method Details

#attr_attrib(*args) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/chiketto/attr_attribute.rb', line 8

def attr_attrib(*args)
  args.map do |value|
    define_method value.to_s do
      Chiketto::Attribute.new instance_variable_get("@#{value}")
    end
  end
end

#attr_date(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chiketto/attr_attribute.rb', line 16

def attr_date(*args)
  args.map do |value|
    define_method value.to_s do
      date = instance_variable_get("@#{value}")
      return date if date.nil?

      if date.is_a?(Hash)
        date = date['utc']
        DateTime.strptime date, '%FT%T'
      else
        DateTime.strptime date, '%FT%TZ'
      end
    end
  end
end