Sha256: b84a34a08d9dbd4912c505880030a3b1bb7d301f3aa9cbb7b482127cc2208777

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# To change this template, choose Tools | Templates
# and open the template in the editor.
module Jiralicious
  class Field < Jiralicious::Base

    def initialize(decoded_json, default = nil, &blk)
      @loaded = false
      if decoded_json.is_a? Hash
        decoded_json = properties_from_hash(decoded_json)
        super(decoded_json)
        parse!(decoded_json)
        self.each do |k, v|
          if v.is_a? Hash
            self[k] = self.class.new(v)
          elsif v.is_a? Array
            v.each_index do |i|
              if v[i].is_a? Hash
                v[i] = self.class.new(v[i])
              end
            end
            self[k] = v
          end
        end
        @loaded = true
      else
        decoded_json.each do |list|
          if numeric? list['id']
            id =  :"id_#{list['id']}"
          else
            id = :"#{list['id']}"
          end
          self.class.property id
          out self.class.new(list)
          self.merge!({id => out})
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jiralicious-0.2.0 lib/jiralicious/field.rb