Class: OpenBD::Resources::Onix::CollateralDetail

Inherits:
BaseResource
  • Object
show all
Defined in:
lib/openbd/resources/onix/collateral_detail.rb

Overview

Block 2: Marketing collateral detail

商品の付帯項目について記述する。

Instance Attribute Summary collapse

Attributes inherited from BaseResource

#src

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ CollateralDetail

Returns a new instance of CollateralDetail.



27
28
29
30
31
32
33
34
35
# File 'lib/openbd/resources/onix/collateral_detail.rb', line 27

def initialize(src)
  super
  @short_description = nil
  @description = nil
  @toc = nil
  @cover = []
  @image = []
  parse(src)
end

Instance Attribute Details

#coverObject (readonly)

Front cover (書影)



22
23
24
# File 'lib/openbd/resources/onix/collateral_detail.rb', line 22

def cover
  @cover
end

#descriptionObject (readonly)

Description (内容紹介2(読者/仕入参考用))



16
17
18
# File 'lib/openbd/resources/onix/collateral_detail.rb', line 16

def description
  @description
end

#imageObject (readonly)

Product image / Artwork (付録、商品イメージ)



25
26
27
# File 'lib/openbd/resources/onix/collateral_detail.rb', line 25

def image
  @image
end

#short_descriptionObject (readonly)

Short description/annotation (内容紹介1(取次広報誌(書店向)用))



13
14
15
# File 'lib/openbd/resources/onix/collateral_detail.rb', line 13

def short_description
  @short_description
end

#tocObject (readonly)

Table of Contents (目次)



19
20
21
# File 'lib/openbd/resources/onix/collateral_detail.rb', line 19

def toc
  @toc
end

Instance Method Details

#parse(cd) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/openbd/resources/onix/collateral_detail.rb', line 37

def parse(cd)
  if cd["TextContent"]
    cd["TextContent"].each do |text|

      # ONIX Code Lists: List 153: Text type
      # https://onix-codelists.io/codelist/153
      case text["TextType"]
      when "02" ## Short Description/annotation
        @short_description = text["Text"]
      when "03" ## Description
        @description = text["Text"]
      when "04" ## TableOfContents
        @toc = text["Text"]
      end
    end
  end

  if cd["SupportingResource"] # 書影や付録などの画像ファイル
    cover = []
    image = []
    # 画像ファイルは3つまで指定可能
    cd["SupportingResource"].each do |sr|

      # Onix codelists List 158: Resource content type
      # https://onix-codelists.io/codelist/158
      if sr["ResourceContentType"] == "01" # Front cover
        cover.push(sr["ResourceVersion"][0]["ResourceLink"])
      end
      if sr["ResourceContentType"] == "07" # Product image / artwork
        image.push(sr["ResourceVersion"][0]["ResourceLink"])
      end
    end
    if cover.length > 0
      @cover = cover
    end
    if image.length > 0
      @image = image
    end
  end
end