Module: YFantasy::Transformations::T
- Extended by:
- Dry::Transformer::Registry
- Defined in:
- lib/y_fantasy/transformations/t.rb
Class Method Summary collapse
- .dig_value(data, *keys) ⇒ Object
- .floatize(value) ⇒ Object
- .no_op(data) ⇒ Object
- .pluralize(jawn) ⇒ Object
- .singularize(jawn) ⇒ Object
- .wrap_in_array(data) ⇒ Object
Class Method Details
.dig_value(data, *keys) ⇒ Object
28 29 30 31 32 |
# File 'lib/y_fantasy/transformations/t.rb', line 28 def self.dig_value(data, *keys) raise ArgumentError, "Data must be a Hash, but it was #{data.class}: #{data.inspect}" unless data.is_a?(Hash) data&.dig(*keys) end |
.floatize(value) ⇒ Object
24 25 26 |
# File 'lib/y_fantasy/transformations/t.rb', line 24 def self.floatize(value) (value == "-") ? 0.0 : Types::Coercible::Float.call(value) end |
.no_op(data) ⇒ Object
41 42 43 |
# File 'lib/y_fantasy/transformations/t.rb', line 41 def self.no_op(data) data end |
.pluralize(jawn) ⇒ Object
14 15 16 17 |
# File 'lib/y_fantasy/transformations/t.rb', line 14 def self.pluralize(jawn) jawn = jawn.to_s jawn.end_with?("s") ? jawn : "#{jawn}s" end |
.singularize(jawn) ⇒ Object
19 20 21 22 |
# File 'lib/y_fantasy/transformations/t.rb', line 19 def self.singularize(jawn) jawn = jawn.to_s jawn.end_with?("s") ? jawn[0...-1] : jawn end |
.wrap_in_array(data) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/y_fantasy/transformations/t.rb', line 34 def self.wrap_in_array(data) return data if data.is_a?(Array) return [] if data.nil? [data] end |