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

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

Constant Summary collapse

ATTRIBUTES =

Informacja o fragmencie publikacji (e-book)

[
  :file_type, :file_size, :md5, :updated_at, :link
]
RELATIONS =
[
  :inspect_include_fields
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ExcerptInfo

Returns a new instance of ExcerptInfo.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 21

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 = Time.parse(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::ContentDateRole::LAST_UPDATED }

    if last_updated_node
      @updated_at = Time.parse(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.



19
20
21
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 19

def eid
  @eid
end

#file_sizeObject

Returns the value of attribute file_size.



19
20
21
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 19

def file_size
  @file_size
end

#file_typeObject

Returns the value of attribute file_type.



19
20
21
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 19

def file_type
  @file_type
end

Returns the value of attribute link.



19
20
21
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 19

def link
  @link
end

#md5Object

Returns the value of attribute md5.



19
20
21
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 19

def md5
  @md5
end

#to_xmlObject

Returns the value of attribute to_xml.



19
20
21
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 19

def to_xml
  @to_xml
end

#updated_atObject

Returns the value of attribute updated_at.



19
20
21
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 19

def updated_at
  @updated_at
end

Instance Method Details

#inspect_include_fieldsObject



55
56
57
# File 'lib/elibri_onix/onix_3_0/excerpt_info.rb', line 55

def inspect_include_fields
  [:link]
end