Class: Centaman::Attribute
- Inherits:
-
Object
- Object
- Centaman::Attribute
- Defined in:
- lib/centaman/attribute.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
-
#centaman_key ⇒ Object
readonly
Returns the value of attribute centaman_key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #age_group ⇒ Object
- #boolean ⇒ Object
- #centaman_description ⇒ Object
- #datetime ⇒ Object
- #display_age_group ⇒ Object
- #display_time ⇒ Object
- #float ⇒ Object
-
#initialize(args = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #integer ⇒ Object
- #parse_value ⇒ Object
- #string ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 11 |
# File 'lib/centaman/attribute.rb', line 7 def initialize(args = {}) @centaman_key = args[:centaman_key] @app_key = args[:app_key] @type = args.fetch(:type, :string) end |
Instance Attribute Details
#app_key ⇒ Object (readonly)
Returns the value of attribute app_key.
4 5 6 |
# File 'lib/centaman/attribute.rb', line 4 def app_key @app_key end |
#centaman_key ⇒ Object (readonly)
Returns the value of attribute centaman_key.
4 5 6 |
# File 'lib/centaman/attribute.rb', line 4 def centaman_key @centaman_key end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/centaman/attribute.rb', line 4 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/centaman/attribute.rb', line 5 def value @value end |
Instance Method Details
#age_group ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/centaman/attribute.rb', line 53 def age_group return 'adult' if value.downcase.include?('adult') return 'child' if value.downcase.include?('child') return 'youth' if value.downcase.include?('youth') return 'senior' if value.downcase.include?('senior') return 'adult' end |
#boolean ⇒ Object
30 31 32 |
# File 'lib/centaman/attribute.rb', line 30 def boolean value end |
#centaman_description ⇒ Object
38 39 40 |
# File 'lib/centaman/attribute.rb', line 38 def centaman_description value end |
#datetime ⇒ Object
34 35 36 |
# File 'lib/centaman/attribute.rb', line 34 def datetime DateTime.parse(value) end |
#display_age_group ⇒ Object
61 62 63 |
# File 'lib/centaman/attribute.rb', line 61 def display_age_group age_group.capitalize end |
#display_time ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/centaman/attribute.rb', line 42 def display_time array = value.split(":") hour = array[0].try(:to_i) minute = array[1].try(:to_i) period = hour >= 12 ? 'pm' : 'am' hour = hour > 12 ? hour - 12 : hour return "#{hour}#{period}" if minute == 0 "#{hour}:#{minute}#{period}" # return [array.first, array[1]].join(":") end |
#float ⇒ Object
22 23 24 |
# File 'lib/centaman/attribute.rb', line 22 def float value end |
#integer ⇒ Object
26 27 28 |
# File 'lib/centaman/attribute.rb', line 26 def integer value.try(:to_i) end |
#parse_value ⇒ Object
13 14 15 16 |
# File 'lib/centaman/attribute.rb', line 13 def parse_value parsed_value = send(type) @value = parsed_value end |
#string ⇒ Object
18 19 20 |
# File 'lib/centaman/attribute.rb', line 18 def string value end |