class Graphlyte::Arguments::Set
Attributes
values[R]
Public Class Methods
new(data)
click to toggle source
# File lib/graphlyte/arguments/set.rb, line 10 def initialize(data) raise ArgumentError, "input #{data} must be a hash" unless data.nil? || data.is_a?(Hash) @values = expand_arguments(data) unless data.nil? end
Public Instance Methods
extract_variables(values=@values, variables=[])
click to toggle source
# File lib/graphlyte/arguments/set.rb, line 15 def extract_variables(values=@values, variables=[]) values&.each do |key, value| if value.is_a?(Set) variables.concat extract_variables(value.values) elsif value.is_a?(Array) elsif value.symbol? variables << value elsif value.formal? variables << value end end variables end
to_h(inner = false)
click to toggle source
# File lib/graphlyte/arguments/set.rb, line 29 def to_h(inner = false) return {} unless values && !values.empty? values.inject({}) do |memo, (k, v)| if v.is_a?(Array) memo[k.to_s.to_camel_case] = v.map(&:to_s) elsif v.is_a?(Set) memo[k.to_s.to_camel_case] = v.to_h else memo[k.to_s.to_camel_case] = v.to_s end memo end end
to_s(inner = false)
click to toggle source
# File lib/graphlyte/arguments/set.rb, line 43 def to_s(inner = false) return "" unless values && !values.empty? arr = stringify_arguments return arr.join(", ") if inner "(#{arr.join(", ")})" end
Private Instance Methods
expand_arguments(data)
click to toggle source
# File lib/graphlyte/arguments/set.rb, line 64 def expand_arguments(data) data.inject({}) do |memo, (k, v)| if v.is_a?(Array) memo[k] = v.map do |item| if item.is_a?(Value) item else Value.new(item) end end elsif v.is_a?(Hash) memo[k] = Set.new(v) else if v.is_a?(Value) memo[k] = v else memo[k] = Value.new(v) end end memo end end
stringify_arguments()
click to toggle source
# File lib/graphlyte/arguments/set.rb, line 52 def stringify_arguments values.map do |k,v| if v.is_a?(Array) "#{k.to_s.to_camel_case}: [#{v.map(&:to_s).join(", ")}]" elsif v.is_a?(Set) "#{k.to_s.to_camel_case}: { #{v.to_s(true)} }" else "#{k.to_s.to_camel_case}: #{v.to_s}" end end end