Module: OnixHelpers::InstanceMethods

Defined in:
lib/elibri_onix_mocks/onix_helpers.rb

Instance Method Summary collapse

Instance Method Details

#audience_range_present?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 130

def audience_range_present?
  self.audience_age_from.present? or self.audience_age_to.present?
end

#authorship_kindObject



135
136
137
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 135

def authorship_kind
  value = self.method_missing(:authorship_kind) || ActiveSupport::StringInquirer.new(:user_given.to_s)
end

#current_stateObject

hack wynikający z nieobecności maszyny stanów



77
78
79
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 77

def current_state
  state
end

#epub_technical_protectionObject



122
123
124
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 122

def epub_technical_protection
  Elibri::ONIX::Dict::Release_3_0::EpubTechnicalProtection.find_by_onix_code(self.epub_technical_protection_onix_code)
end

#formObject



114
115
116
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 114

def form
  Elibri::ONIX::Dict::Release_3_0::ProductFormCode.find_by_onix_code(self.product_form_onix_code)
end

#form_detailObject



126
127
128
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 126

def form_detail
  Elibri::ONIX::Dict::Release_3_0::ProductFormDetail.find_by_onix_code(self.product_form_detail_onix_code)
end

#notification_typeObject

TODO



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 64

def notification_type
  if current_state == :private
    raise "Cannot handle private state"
  elsif current_state == :announced
    Elibri::ONIX::Dict::Release_3_0::NotificationType.find_by_onix_code(Elibri::ONIX::Dict::Release_3_0::NotificationType::EARLY_NOTIFICATION)
  elsif current_state == :preorder
    Elibri::ONIX::Dict::Release_3_0::NotificationType.find_by_onix_code(Elibri::ONIX::Dict::Release_3_0::NotificationType::ADVANCED_NOTIFICATION)
  else
    Elibri::ONIX::Dict::Release_3_0::NotificationType.find_by_onix_code(Elibri::ONIX::Dict::Release_3_0::NotificationType::CONFIRMED_ON_PUBLICATION)
  end
end

#publication_date(format = :onix, splitter = nil) ⇒ Object

Zwróć datę publikacji w formacie ONIX



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 20

def publication_date(format = :onix, splitter = nil)
  publication_year_str = self.publication_year ? "%04d"% self.publication_year : nil
  publication_month_str = self.publication_month ? "%02d"% self.publication_month : nil
  publication_day_str = self.publication_day ? "%02d"% self.publication_day : nil

  case format
    when :onix
      splitter ||= ''
      date_string = [publication_year_str, publication_month_str, publication_day_str].compact.join(splitter)
    when :polish
      splitter ||= '.'
      date_string = [publication_day_str, publication_month_str, publication_year_str].compact.join(splitter)
  end
  date_string.blank? ? nil : date_string
end

#publication_date=(date_from_xml) ⇒ Object

Parsuj datę publikacji z ONIX`a (YYYYMMDD) i uzupełnij odpowiednie pola



52
53
54
55
56
57
58
59
60
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 52

def publication_date=(date_from_xml)
  if match = date_from_xml.to_s.match(/ (\d{4}) [\s-]? (\d{2})? [\s-]? (\d{2})? /x)
    self.publication_year = $1
    self.publication_month = $2
    self.publication_day = $3
  else
    self.publication_year = self.publication_month = self.publication_day = nil if date_from_xml.blank?
  end
end

#publication_date_with_onix_format_codeObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 37

def publication_date_with_onix_format_code
   #lista 55
   if self.publication_year.present? && self.publication_month.present? && self.publication_day.present?
     [publication_date, Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMMDD]
   elsif self.publication_year.present? && self.publication_month.present?
     [self.publication_year.to_s + "%02d" % self.publication_month, Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYYMM] 
   elsif self.publication_year.present?
     [self.publication_year.to_s, Elibri::ONIX::Dict::Release_3_0::DateFormat::YYYY]
   else
     [nil, nil]
   end
end

#publishing_statusObject



118
119
120
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 118

def publishing_status
  Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode.find_by_onix_code(self.publishing_status_onix_code)
end

#publishing_status_onix_codeObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 82

def publishing_status_onix_code
  if current_state.to_sym == :private #domyślny stan
    raise "Cannot handle private state"
  elsif current_state.to_sym == :announced    #zapowiedź
    Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode::FORTHCOMING
  elsif current_state.to_sym == :preorder     #przedsprzedaż
    Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode::FORTHCOMING
  elsif current_state.to_sym == :published    #dostępna na rynku
    Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode::ACTIVE
  elsif current_state.to_sym == :out_of_print #nakład wyczerpany
    Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode::OUT_OF_PRINT
  elsif current_state.to_sym == :deleted      #błędnie stworzony rekord
    Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode::UNSPECIFIED
  else
    raise "Don't know how to handle state = #{current_state}"
  end
end

#publishing_status_onix_code=(code) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 100

def publishing_status_onix_code=(code)
  if code.present?
    if code == Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode::ACTIVE
      self.state = "published"
    elsif code == Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode::OUT_OF_PRINT
      self.state = "out_of_print"
    elsif code == Elibri::ONIX::Dict::Release_3_0::PublishingStatusCode::FORTHCOMING
      self.state = "preorder"
    else
      raise "Don't know how to handle publishing_stats_onix_code = #{code}"
    end
  end
end

#series_membership_kindObject



140
141
142
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 140

def series_membership_kind
  value = self.method_missing(:series_membership_kind) || ActiveSupport::StringInquirer.new(:user_given.to_s)
end

#series_namesObject



145
146
147
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 145

def series_names
  self.series_memberships.map {|series_membership| series_membership.publisher_series.try(:name)}.compact
end

#stock_quantity_for_merlinObject



149
150
151
152
153
154
155
156
157
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 149

def stock_quantity_for_merlin
  if stock_quantity.nil?
    0
  elsif stock_quantity > 50
    50
  else
    stock_quantity
  end
end

#title_partsObject

zwróć różne poziomy tytułu, w formacie potrzebnym do exportu w ONIX-ie



9
10
11
12
13
14
15
16
# File 'lib/elibri_onix_mocks/onix_helpers.rb', line 9

def title_parts
  [].tap do |res|
    product_code =  Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::PRODUCT      #01
    collection_code = Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::COLLECTION #02
    res << OpenStruct.new(:level => collection_code, :title => collection.name, :part => self.collection_part) if collection
    res << OpenStruct.new(:level => product_code, :title => self.title, :subtitle => self.subtitle, :part => self.title_part) if self.title.present?
  end
end