naffis / ddex

DDEX metadata serialization for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DDEX

<img src=“https://secure.travis-ci.org/sshaw/ddex.png”/>

DDEX metadata serialization for Ruby

Overview

require "ddex"

message = DDEX.read("path/to/metadata.xml")
puts message.update_indicator
message.resource_list.each do |resource|
  puts resource.title
  puts resource.details.size
end

puts "Supported!" if DDEX.supports?("ern/341")

message = DDEX.read(string)
message = DDEX.read(io)
# ...

include DDEX::ERN::V341   # v3.4.1
message = NewReleaseMessage.new(hash)
record  = SoundRecording.new
record.language_and_script_code = "en-US"
# ...

image = Image.new
image.type = "FrontCoverImage"
# ...

message.resource_list << image
message.resource_list << record
p message.to_hash

xml = DDEX.write(message)
File.open("bloat.xml", "w") { |io| io.puts(xml) }

How this differs from the spec

Every DDEX version handled by this module is fully supported, but there are some things you’ll need to know.

Naming conventions

DDEX elements and attributes use the CamelCase naming convention, this module uses Ruby naming conversions: CamelCase for classes, and snake_case for class attributes. For example, this DDEX XML:

<PartyName>
  <FullName>sshaw</FullName>
</PartyName>

Would be manipulated via:

party = PartyName.new(:full_name => "sshaw")
puts party.full_name
party.full_name = "gwozdzie"

See also Boolean elements and attributes

Cardinally

Elements that can occur more than once will be placed in an Array and their parent classes’ accessor methods will use the plural form of the element/attribute’s name. For example:

<Release>
  <!-- More data -->
  <PLine>
    <Year>1994</Year>
    <PLineText>Track Copyright</PLineText>
  </PLine>
  <PLine>
    <Year>2001</Year>
    <PLineText>Another Track Copyright</PLineText>
  </PLine>
</Release>

Would be manipulated via:

release.p_lines.each { |line| puts line.p_line_text }
release.p_lines << PLine.new(:year => 1999)

There are a few -hopefully obvious- exceptions. If the DDEX name indicates that its a collection, it’s left alone. SoundRecordingDetailsByTerritory and ResourceList come to mind.

Boolean elements and attributes

The following are applied to accessors derived from DDEX elements and attributes with an XML schema type of boolean:

  • "Is" is removed from the beginning of the name

  • The reader method is turned into a predicate accessor, i.e., has a "?" appended to it

For example, SoundRecording/IsArtistRelated:

recording = SoundRecording.new(:artist_related => true)
p recording.artist_related?  # true
recording.artist_related = false

TODO: See Types

Version specific changes

ERN v3.6

ern:PriceInformation/@PriceType has been renamed to @Type to avoid conflicting with the element of the same name (ern:PriceInformation/PriceType)

More Info

TODO

Many things… but: ROXML.from_xml does not check the root element’s name. Need to add something like:

raise "unknown element #{xml.name}" unless xml.name == tag_name

About

DDEX metadata serialization for Ruby


Languages

Language:Ruby 99.9%Language:HTML 0.1%