Class: Scopie::Value

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hashObject

Returns the value of attribute hash

Returns:

  • (Object)

    the current value of hash



3
4
5
# File 'lib/scopie/value.rb', line 3

def hash
  @hash
end

#key_nameObject

Returns the value of attribute key_name

Returns:

  • (Object)

    the current value of key_name



3
4
5
# File 'lib/scopie/value.rb', line 3

def key_name
  @key_name
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



3
4
5
# File 'lib/scopie/value.rb', line 3

def options
  @options
end

Instance Method Details

#coercedObject



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

def coerced
  coerce_to_type(raw, fetch_type)
end

#fetch_defaultObject



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

def fetch_default
  options[:default]
end

#fetch_typeObject



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

def fetch_type
  options[:type]
end

#given?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/scopie/value.rb', line 28

def given?
  key_passed? || has_default?
end

#has_default?Boolean

Returns:

  • (Boolean)


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

def has_default?
  options.key?(:default)
end

#key_passed?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/scopie/value.rb', line 32

def key_passed?
  hash.key?(key_name)
end

#present?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/scopie/value.rb', line 36

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

#rawObject



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

def raw
  return hash[key_name] if hash.key?(key_name)
  fetch_default
end