Module: Monolens::Lens
- Included in:
- Array::Compact, Array::Join, Array::Map, Coerce::Date, Coerce::DateTime, Core::Chain, Core::Mapping, File, Object::Keys, Object::Rename, Object::Select, Object::Transform, Object::Values, Skip::Null, Str::Downcase, Str::Split, Str::Strip, Str::Upcase
- Defined in:
- lib/monolens/lens.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #fetch_on(attr, arg) ⇒ Object
- #initialize(options = {}) ⇒ Object
- #is_array!(arg) ⇒ Object
- #is_enumerable!(arg) ⇒ Object
- #is_hash!(arg) ⇒ Object
- #is_string!(arg) ⇒ Object
- #option(name, default = nil) ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/monolens/lens.rb', line 8 def @options end |
Instance Method Details
#fetch_on(attr, arg) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/monolens/lens.rb', line 10 def fetch_on(attr, arg) if arg.key?(attr) [ attr, arg[attr] ] elsif arg.key?(attr_s = attr.to_s) [ attr_s, arg[attr_s] ] elsif arg.key?(attr_sym = attr.to_sym) [ attr_sym, arg[attr_sym] ] else [ attr, nil ] end end |
#initialize(options = {}) ⇒ Object
3 4 5 6 7 |
# File 'lib/monolens/lens.rb', line 3 def initialize( = {}) @options = .each_with_object({}){|(k,v),memo| memo[k.to_sym] = v } end |
#is_array!(arg) ⇒ Object
45 46 47 48 49 |
# File 'lib/monolens/lens.rb', line 45 def is_array!(arg) return if arg.is_a?(::Array) raise Monolens::Error, "Array expected, got #{arg.class}" end |
#is_enumerable!(arg) ⇒ Object
39 40 41 42 43 |
# File 'lib/monolens/lens.rb', line 39 def is_enumerable!(arg) return if arg.is_a?(::Enumerable) raise Monolens::Error, "Enumerable expected, got #{arg.class}" end |
#is_hash!(arg) ⇒ Object
33 34 35 36 37 |
# File 'lib/monolens/lens.rb', line 33 def is_hash!(arg) return if arg.is_a?(::Hash) raise Monolens::Error, "Hash expected, got #{arg.class}" end |
#is_string!(arg) ⇒ Object
27 28 29 30 31 |
# File 'lib/monolens/lens.rb', line 27 def is_string!(arg) return if arg.is_a?(::String) raise Monolens::Error, "String expected, got #{arg.class}" end |
#option(name, default = nil) ⇒ Object
22 23 24 25 |
# File 'lib/monolens/lens.rb', line 22 def option(name, default = nil) _, option = fetch_on(name, ) option.nil? ? default : option end |