Class: Elibri::ONIX::Dict::CoverType

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

Constant Summary collapse

ALL =
YAML::load_file(conf)
HARDBACK =
8
PLASTIC =
6
PAPERBACK =
4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (readonly)

id to wartość jaka będzie zapisana w polu cover_type_id dla produktu. name to nazwa w obrębie Elibri



11
12
13
# File 'lib/elibri_onix_dict/cover_type.rb', line 11

def id
  @id
end

#keyObject (readonly)

id to wartość jaka będzie zapisana w polu cover_type_id dla produktu. name to nazwa w obrębie Elibri



11
12
13
# File 'lib/elibri_onix_dict/cover_type.rb', line 11

def key
  @key
end

#product_formObject (readonly)

id to wartość jaka będzie zapisana w polu cover_type_id dla produktu. name to nazwa w obrębie Elibri



11
12
13
# File 'lib/elibri_onix_dict/cover_type.rb', line 11

def product_form
  @product_form
end

#product_form_detailObject (readonly)

id to wartość jaka będzie zapisana w polu cover_type_id dla produktu. name to nazwa w obrębie Elibri



11
12
13
# File 'lib/elibri_onix_dict/cover_type.rb', line 11

def product_form_detail
  @product_form_detail
end

Class Method Details

.allObject



44
45
46
# File 'lib/elibri_onix_dict/cover_type.rb', line 44

def self.all
  ALL
end

.determine_cover_type(product_form, product_form_detail) ⇒ Object



29
30
31
32
# File 'lib/elibri_onix_dict/cover_type.rb', line 29

def self.determine_cover_type(product_form, product_form_detail)
  matching_cover = all.find { |cover| cover.product_form == product_form && cover.product_form_detail == product_form_detail }
  I18n::t("products.cover_type.#{matching_cover.key}") if matching_cover
end

.find(cover_type_id) ⇒ Object



25
26
27
# File 'lib/elibri_onix_dict/cover_type.rb', line 25

def self.find(cover_type_id)
  self.all.find {|cover_type| cover_type.id == cover_type_id }
end

.most_similar_to(cover_name) ⇒ Object

Znajdź w słowniku typ okładki, którego nazwa jest najbardziej podobna do podanego stringu.



35
36
37
38
39
40
41
# File 'lib/elibri_onix_dict/cover_type.rb', line 35

def self.most_similar_to(cover_name)
  if cover_name =~ /karton/
    return all.find { |c| c.name == "twarda" }
  else
    all.sort_by {|cover_type| cover_type.name.downcase.levenshtein_similar(cover_name.downcase) }.last
  end
end

Instance Method Details

#nameObject



21
22
23
# File 'lib/elibri_onix_dict/cover_type.rb', line 21

def name
  I18n::t("products.cover_type.#{key}")
end