class Thinreports::SectionReport::Schema::Parser
Attributes
schema_data[R]
Public Instance Methods
parse(schema_json_data)
click to toggle source
# File lib/thinreports/section_report/schema/parser.rb, line 12 def parse(schema_json_data) schema_data = JSON.parse(schema_json_data) section_schema_datas = schema_data['sections'].group_by { |section| section['type'] } Schema::Report.new( schema_data, headers: parse_sections(:header, section_schema_datas['header']), details: parse_sections(:detail, section_schema_datas['detail']), footers: parse_sections(:footer, section_schema_datas['footer']) ) end
Private Instance Methods
parse_section(type, section_schema_data)
click to toggle source
# File lib/thinreports/section_report/schema/parser.rb, line 38 def parse_section(type, section_schema_data) items = section_schema_data['items'].map do |item_schema_data| item_type = item_schema_data['type'] Core::Shape::Format(item_type).new(item_schema_data) end section_schema_class_for(type).new(section_schema_data, items: items) end
parse_sections(section_type, section_schema_datas = nil)
click to toggle source
# File lib/thinreports/section_report/schema/parser.rb, line 29 def parse_sections(section_type, section_schema_datas = nil) return {} if section_schema_datas.nil? section_schema_datas.each_with_object({}) do |section_schema_data, section_schemas| id = section_schema_data['id'] section_schemas[id.to_sym] = parse_section(section_type, section_schema_data) end end
section_schema_class_for(section_type)
click to toggle source
# File lib/thinreports/section_report/schema/parser.rb, line 46 def section_schema_class_for(section_type) Schema::Section.const_get(section_type.capitalize) end