Sha256: bbc85d7b2ff5d474ad16caa970f1c7dfada0ad1186c81360712a20145068e869

Contents?: true

Size: 1.23 KB

Versions: 23

Compression:

Stored size: 1.23 KB

Contents

module Centaman
  #:nodoc:
  class Attribute
    attr_reader :centaman_key, :app_key, :type
    attr_accessor :value

    def initialize(args = {})
      @centaman_key = args[:centaman_key]
      @app_key = args[:app_key]
      @type = args.fetch(:type, :string)
    end

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

    def string
      value
    end

    def float
      value
    end

    def integer
      value.try(:to_i)
    end

    def boolean
      value
    end

    def datetime
      DateTime.parse(value)
    end

    def centaman_description
      value
    end

    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

    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 'adult'
    end

    def display_age_group
      age_group.capitalize
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
centaman-5.0.1 lib/centaman/attribute.rb
centaman-5.0.0 lib/centaman/attribute.rb
centaman-4.0.5 lib/centaman/attribute.rb
centaman-4.0.4 lib/centaman/attribute.rb
centaman-4.0.3 lib/centaman/attribute.rb
centaman-4.0.2 lib/centaman/attribute.rb
centaman-4.0.1 lib/centaman/attribute.rb
centaman-3.1.2 lib/centaman/attribute.rb
centaman-3.1.1 lib/centaman/attribute.rb
centaman-3.1.0 lib/centaman/attribute.rb
centaman-3.0.0 lib/centaman/attribute.rb
centaman-2.1.0 lib/centaman/attribute.rb
centaman-2.0.0 lib/centaman/attribute.rb
centaman-1.0.0 lib/centaman/attribute.rb
centaman-0.2.3 lib/centaman/attribute.rb
centaman-0.2.2 lib/centaman/attribute.rb
centaman-0.2.1 lib/centaman/attribute.rb
centaman-0.2.0 lib/centaman/attribute.rb
centaman-0.1.13 lib/centaman/attribute.rb
centaman-0.1.12 lib/centaman/attribute.rb