class Voucher::SegmentsParser
Public Class Methods
call(json)
click to toggle source
# File lib/voucher/segments_parser.rb, line 5 def self.call(json) new(json).call end
new(json)
click to toggle source
# File lib/voucher/segments_parser.rb, line 9 def initialize(json) @json = json end
Public Instance Methods
call()
click to toggle source
# File lib/voucher/segments_parser.rb, line 13 def call parse end
Private Instance Methods
parse()
click to toggle source
# File lib/voucher/segments_parser.rb, line 19 def parse content = segments_from_json SegmentsBuilder.call( election: content[:included]&.first, segments: content[:data] ) end
segments_from_json()
click to toggle source
# File lib/voucher/segments_parser.rb, line 28 def segments_from_json parsed_json = JSON.parse(@json) underscore_keys(parsed_json).with_indifferent_access end
underscore_keys(parsed_json)
click to toggle source
# File lib/voucher/segments_parser.rb, line 34 def underscore_keys(parsed_json) parsed_json.deep_transform_keys { |key| key.to_s.underscore } end