Class: Scopie::Value
- Inherits:
-
Struct
- Object
- Struct
- Scopie::Value
- Defined in:
- lib/scopie/value.rb
Constant Summary collapse
- TRUE_VALUES =
['true', true, '1', 1].freeze
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#key_name ⇒ Object
Returns the value of attribute key_name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #coerced ⇒ Object
- #fetch_default ⇒ Object
- #fetch_type ⇒ Object
- #given? ⇒ Boolean
- #has_default? ⇒ Boolean
- #key_passed? ⇒ Boolean
- #present? ⇒ Boolean
- #raw ⇒ Object
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash
3 4 5 |
# File 'lib/scopie/value.rb', line 3 def hash @hash end |
#key_name ⇒ Object
Returns the value of attribute key_name
3 4 5 |
# File 'lib/scopie/value.rb', line 3 def key_name @key_name end |
#options ⇒ Object
Returns the value of attribute options
3 4 5 |
# File 'lib/scopie/value.rb', line 3 def @options end |
Instance Method Details
#coerced ⇒ Object
12 13 14 |
# File 'lib/scopie/value.rb', line 12 def coerced coerce_to_type(raw, fetch_type) end |
#fetch_default ⇒ Object
20 21 22 |
# File 'lib/scopie/value.rb', line 20 def fetch_default [:default] end |
#fetch_type ⇒ Object
16 17 18 |
# File 'lib/scopie/value.rb', line 16 def fetch_type [:type] end |
#given? ⇒ Boolean
28 29 30 |
# File 'lib/scopie/value.rb', line 28 def given? key_passed? || has_default? end |
#has_default? ⇒ Boolean
24 25 26 |
# File 'lib/scopie/value.rb', line 24 def has_default? .key?(:default) end |
#key_passed? ⇒ Boolean
32 33 34 |
# File 'lib/scopie/value.rb', line 32 def key_passed? hash.key?(key_name) end |
#present? ⇒ Boolean
36 37 38 39 |
# File 'lib/scopie/value.rb', line 36 def present? value = raw value.respond_to?(:empty?) ? !value.empty? : !!value end |
#raw ⇒ Object
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 |