Sha256: 1c82e92cbdd27ca74fc1c9a4c09272e0cf3c9b5324c25cc375f86042cfe93a12

Contents?: true

Size: 1.13 KB

Versions: 15

Compression:

Stored size: 1.13 KB

Contents

require 'jbuilder'

require_relative 'mdJson_base'
require_relative 'mdJson_timePeriod'

module ADIWG
  module Mdtranslator
    module Writers
      module MdJson
        module TemporalElement
          extend MdJson::Base

          def self.build(intObj)
            remap = {
              date: [],
              timeInstant: [],
              timePeriod: []
            }

            intObj.each do |obj|
              obj.each { |key, value| remap[key] << value unless value.empty? }
            end

            Jbuilder.new do |json|
              json.timeInstant(remap[:timeInstant]) do |ti|
                json.id ti[:timeId]
                json.description ti[:description]
                json.timePosition ti[:timePosition][:dateTime] unless ti[:timePosition].nil?
              end unless remap[:timeInstant].empty?
              json.timePeriod json_map(remap[:timePeriod], TimePeriod)
              json.date(remap[:date]) { |dt| json.merge! dt[:dateTime] } unless remap[:date].empty?
            end unless remap[:date].empty? && remap[:timeInstant].empty? && remap[:timePeriod].empty?
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
adiwg-mdtranslator-1.4.0 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta14 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta13 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta12 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta11 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta10 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta9 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta8 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta7 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta6 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta5 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta4 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta3 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta2 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb
adiwg-mdtranslator-1.4.0.beta1 lib/adiwg/mdtranslator/writers/mdJson/sections/mdJson_temporalElement.rb