Class: WCC::Contentful::IndexedRepresentation::ContentType

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc/contentful/indexed_representation.rb

Constant Summary collapse

ATTRIBUTES =
%i[
  name
  content_type
  fields
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_id = nil) ⇒ ContentType

Returns a new instance of ContentType.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wcc/contentful/indexed_representation.rb', line 56

def initialize(hash_or_id = nil)
  @fields = {}
  return unless hash_or_id

  if hash_or_id.is_a?(String)
    @name = hash_or_id
    return
  end

  if raw_fields = (hash_or_id.delete('fields') || hash_or_id.delete(:fields))
    raw_fields.each do |field_name, raw_field|
      @fields[field_name] = Field.new(raw_field)
    end
  end

  hash_or_id.each { |k, v| public_send("#{k}=", v) }
end

Instance Method Details

#==(other) ⇒ Object



82
83
84
# File 'lib/wcc/contentful/indexed_representation.rb', line 82

def ==(other)
  ATTRIBUTES.all? { |att| public_send(att) == other.public_send(att) }
end

#deep_dupObject



74
75
76
77
78
79
80
# File 'lib/wcc/contentful/indexed_representation.rb', line 74

def deep_dup
  dup_hash =
    ATTRIBUTES.each_with_object({}) do |att, h|
      h[att] = public_send(att)
    end
  self.class.new(dup_hash)
end