Class: JsonApiFilter::ValueParser
- Inherits:
-
Object
- Object
- JsonApiFilter::ValueParser
- Defined in:
- lib/json_api_filter/value_parser.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.parse(value) ⇒ Array
Transform string of coma separated values to Array.
Instance Method Summary collapse
- #indifferent_parse ⇒ Object
-
#initialize(value) ⇒ ValueParser
constructor
A new instance of ValueParser.
- #parse ⇒ Object
- #parse_hash ⇒ Object
Constructor Details
#initialize(value) ⇒ ValueParser
Returns a new instance of ValueParser.
7 8 9 |
# File 'lib/json_api_filter/value_parser.rb', line 7 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/json_api_filter/value_parser.rb', line 4 def value @value end |
Class Method Details
.parse(value) ⇒ Array
Transform string of coma separated values to Array
18 19 20 |
# File 'lib/json_api_filter/value_parser.rb', line 18 def self.parse(value) new(value).indifferent_parse end |
Instance Method Details
#indifferent_parse ⇒ Object
22 23 24 25 |
# File 'lib/json_api_filter/value_parser.rb', line 22 def indifferent_parse return parse if value.is_a? String parse_hash if value.is_a? HashWithIndifferentAccess end |
#parse ⇒ Object
27 28 29 30 |
# File 'lib/json_api_filter/value_parser.rb', line 27 def parse return [value] unless value.include?(",") value.split(',') end |
#parse_hash ⇒ Object
32 33 34 |
# File 'lib/json_api_filter/value_parser.rb', line 32 def parse_hash value.map{|k,v| {k => self.class.parse(v)}}.reduce(&:merge) end |