Class: Scopie::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/scopie/value.rb

Constant Summary collapse

TRUE_VALUES =
['true'.freeze, true, '1'.freeze, 1].freeze

Instance Method Summary collapse

Constructor Details

#initialize(hash, key_name, options) ⇒ Value

Returns a new instance of Value.



7
8
9
10
11
# File 'lib/scopie/value.rb', line 7

def initialize(hash, key_name, options)
  @hash = hash
  @key_name = key_name
  @options = options
end

Instance Method Details

#allow_blank?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/scopie/value.rb', line 30

def allow_blank?
  @options[:allow_blank]
end

#coercedObject



17
18
19
# File 'lib/scopie/value.rb', line 17

def coerced
  coerce_to_type(raw, fetch_type)
end

#given?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/scopie/value.rb', line 21

def given?
  key_passed? || has_default?
end

#present?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/scopie/value.rb', line 25

def present?
  value = raw
  value.respond_to?(:empty?) ? !value.empty? : !!value
end

#rawObject



13
14
15
# File 'lib/scopie/value.rb', line 13

def raw
  @hash.fetch(@key_name) { fetch_default }
end