Class: Elibri::ONIX::Release_3_0::ExcerptInfo

Inherits:
Object
  • Object
show all
Includes:
TimestampParser
Defined in:
lib/elibri_onix/onix_3_0/excerpt_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TimestampParser

#parse_timestamp

Constructor Details

#initialize(data) ⇒ ExcerptInfo

Returns a new instance of ExcerptInfo.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 9

def initialize(data)
  @to_xml = data.to_s
  if data.name == "excerpt"
    @file_type = data.attributes['file_type'].value
    @file_size = data.attributes['file_size'].value.to_i
    @md5 = data.attributes['md5'].value
    @updated_at = parse_timestamp(data.attributes['updated_at'].value)
    @link = data.text
    @eid = data.attributes['id'].value.to_i
  elsif data.name == "ResourceVersion"

    last_updated_node = data.css("ContentDate").find { |date|
           date.css("ContentDateRole").first.inner_text == Elibri::ONIX::Dict::Release_3_0::::LAST_UPDATED }

    if last_updated_node
      @updated_at = parse_timestamp(last_updated_node.css("Date").first.inner_text)
    end
    @link = data.css("ResourceLink").first.text
    @eid =  @link.split("/")[4].to_i
    @file_type = @link.split(".").last + "_excerpt"
    data.css("ResourceVersionFeature").each do |feature|
      feature_type = feature.css("ResourceVersionFeatureType").first.inner_text
      feature_value = feature.css("FeatureValue").first.inner_text
      if feature_type == Elibri::ONIX::Dict::Release_3_0::ResourceVersionFeatureType::MD5_HASH_VALUE
        @md5 = feature_value
      elsif feature_type == Elibri::ONIX::Dict::Release_3_0::ResourceVersionFeatureType::SIZE_IN_BYTES
        @file_size = feature_value.to_i
      end
    end
  else
    raise ArgumentError, "Unknow element for ExcerptInfo: #{data.name}"
  end
end

Instance Attribute Details

#eidObject

Returns the value of attribute eid.



7
8
9
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 7

def eid
  @eid
end

#file_sizeObject

Returns the value of attribute file_size.



7
8
9
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 7

def file_size
  @file_size
end

#file_typeObject

Returns the value of attribute file_type.



7
8
9
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 7

def file_type
  @file_type
end

Returns the value of attribute link.



7
8
9
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 7

def link
  @link
end

#md5Object

Returns the value of attribute md5.



7
8
9
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 7

def md5
  @md5
end

#to_xmlObject

Returns the value of attribute to_xml.



7
8
9
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 7

def to_xml
  @to_xml
end

#updated_atObject

Returns the value of attribute updated_at.



7
8
9
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 7

def updated_at
  @updated_at
end

Instance Method Details

#inspect_include_fieldsObject



43
44
45
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 43

def inspect_include_fields
  [:link]
end