Class: Elibri::ONIX::Dict::CoverType
- Inherits:
-
Object
- Object
- Elibri::ONIX::Dict::CoverType
- 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
-
#id ⇒ Object
readonly
id to wartość jaka będzie zapisana w polu cover_type_id dla produktu.
-
#key ⇒ Object
readonly
id to wartość jaka będzie zapisana w polu cover_type_id dla produktu.
-
#product_form ⇒ Object
readonly
id to wartość jaka będzie zapisana w polu cover_type_id dla produktu.
-
#product_form_detail ⇒ Object
readonly
id to wartość jaka będzie zapisana w polu cover_type_id dla produktu.
Class Method Summary collapse
- .all ⇒ Object
- .determine_cover_type(product_form, product_form_detail) ⇒ Object
- .find(cover_type_id) ⇒ Object
-
.most_similar_to(cover_name) ⇒ Object
Znajdź w słowniku typ okładki, którego nazwa jest najbardziej podobna do podanego stringu.
Instance Method Summary collapse
Instance Attribute Details
#id ⇒ Object (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 |
#key ⇒ Object (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_form ⇒ Object (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_detail ⇒ Object (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
.all ⇒ Object
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
#name ⇒ Object
21 22 23 |
# File 'lib/elibri_onix_dict/cover_type.rb', line 21 def name I18n::t("products.cover_type.#{key}") end |