Class: Centaman::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/centaman/attribute.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject (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_keyObject (readonly)

Returns the value of attribute centaman_key.



4
5
6
# File 'lib/centaman/attribute.rb', line 4

def centaman_key
  @centaman_key
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/centaman/attribute.rb', line 4

def type
  @type
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/centaman/attribute.rb', line 5

def value
  @value
end

Instance Method Details

#age_groupObject



53
54
55
56
57
# 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 'adult'
end

#booleanObject



30
31
32
# File 'lib/centaman/attribute.rb', line 30

def boolean
  value
end

#centaman_descriptionObject



38
39
40
# File 'lib/centaman/attribute.rb', line 38

def centaman_description
  value
end

#datetimeObject



34
35
36
# File 'lib/centaman/attribute.rb', line 34

def datetime
  DateTime.parse(value)
end

#display_age_groupObject



59
60
61
# File 'lib/centaman/attribute.rb', line 59

def display_age_group
  age_group.capitalize
end

#display_timeObject



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

#floatObject



22
23
24
# File 'lib/centaman/attribute.rb', line 22

def float
  value
end

#integerObject



26
27
28
# File 'lib/centaman/attribute.rb', line 26

def integer
  value.try(:to_i)
end

#parse_valueObject



13
14
15
16
# File 'lib/centaman/attribute.rb', line 13

def parse_value
  parsed_value = send(type)
  @value = parsed_value
end

#stringObject



18
19
20
# File 'lib/centaman/attribute.rb', line 18

def string
  value
end