Class: Xmpleton::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/xmpleton.rb

Instance Method Summary collapse

Constructor Details

#initialize(image_file) ⇒ Reader

Returns a new instance of Reader.



5
6
7
8
9
10
11
12
13
# File 'lib/xmpleton.rb', line 5

def initialize(image_file)
  image_file = image_file.clone
  image_file.rewind
  binary_data = image_file.read
  xmp_start = binary_data.index '<x:xmpmeta'
  xmp_end = binary_data.index('</x:xmpmeta>')
  @xmp_data = binary_data[xmp_start..xmp_end + 11] if xmp_start and xmp_end
  @xml = Nokogiri::XML.parse(@xmp_data)
end

Instance Method Details

#tagsObject



15
16
17
18
19
20
21
22
23
# File 'lib/xmpleton.rb', line 15

def tags
  tags = []
  subject = @xml.css("dc|subject", 'dc' => 'http://purl.org/dc/elements/1.1/')
  if subject && !subject.empty?
    items = subject.css("rdf|li", 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
    tags = items.map { |i| i.text }
  end
  tags
end