Module: ONIX::Attributes

Included in:
Subset, TextWithAttributes
Defined in:
lib/onix/subset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesHash<String,Code>

Returns:

  • (Hash<String,Code>)


42
43
44
# File 'lib/onix/subset.rb', line 42

def attributes
  @attributes
end

Class Method Details

.attribute_class(attr) ⇒ Class

Parameters:

  • attr (String)

Returns:

  • (Class)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/onix/subset.rb', line 57

def self.attribute_class(attr)
  case attr
  when "sourcename"
    TextAttr
  when "sourcetype"
    RecordSourceType
  when "collationkey"
    TextAttr
  when "dateformat"
    DateFormat
  when "datestamp"
    DateStamp
  when "language"
    LanguageCode
  when "textcase"
    TextCase
  when "textformat"
    TextFormat
  when "textscript"
    ScriptCode
  else
    nil
  end
end

Instance Method Details

#parse_attributes(attrs) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/onix/subset.rb', line 82

def parse_attributes(attrs)
  @attributes ||= {}
  attrs.each do |k, v|
    attr_klass = Attributes.attribute_class(k.to_s)
    @attributes[k.to_s] = attr_klass ? attr_klass.from_code(v.to_s) : nil
  end
end

#serialized_attributesHash<String,String>

Returns:

  • (Hash<String,String>)


45
46
47
48
49
50
51
52
53
# File 'lib/onix/subset.rb', line 45

def serialized_attributes
  if @attributes and @attributes.length > 0
    attrs = {}
    @attributes.each do |k, v|
      attrs[k] = v.code if v
    end
    attrs
  end
end