Class: Oddb2xml::SemanticCheckXML
- Inherits:
-
Object
- Object
- Oddb2xml::SemanticCheckXML
- Defined in:
- lib/oddb2xml/semantic_check.rb
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#components ⇒ Object
Returns the value of attribute components.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#sub_key_names ⇒ Object
readonly
Returns the value of attribute sub_key_names.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #get_items(component_name) ⇒ Object
-
#initialize(filename, components = ["PRODUCTS", "LIMITATIONS", "ITEMS"]) ⇒ SemanticCheckXML
constructor
A new instance of SemanticCheckXML.
- #load_file(name) ⇒ Object
Constructor Details
#initialize(filename, components = ["PRODUCTS", "LIMITATIONS", "ITEMS"]) ⇒ SemanticCheckXML
Returns a new instance of SemanticCheckXML.
14 15 16 17 18 19 20 |
# File 'lib/oddb2xml/semantic_check.rb', line 14 def initialize(filename, components = ["PRODUCTS", "LIMITATIONS", "ITEMS"]) raise "File #{filename} must exist" unless File.exist?(filename) @filename = filename @basename = File.basename(filename) @components = components @hash = load_file(@filename) end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
13 14 15 |
# File 'lib/oddb2xml/semantic_check.rb', line 13 def basename @basename end |
#components ⇒ Object
Returns the value of attribute components.
12 13 14 |
# File 'lib/oddb2xml/semantic_check.rb', line 12 def components @components end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
13 14 15 |
# File 'lib/oddb2xml/semantic_check.rb', line 13 def filename @filename end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
13 14 15 |
# File 'lib/oddb2xml/semantic_check.rb', line 13 def hash @hash end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
13 14 15 |
# File 'lib/oddb2xml/semantic_check.rb', line 13 def keys @keys end |
#sub_key_names ⇒ Object (readonly)
Returns the value of attribute sub_key_names.
13 14 15 |
# File 'lib/oddb2xml/semantic_check.rb', line 13 def sub_key_names @sub_key_names end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/oddb2xml/semantic_check.rb', line 13 def version @version end |
Class Method Details
.get_component_key_name(component_name) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/oddb2xml/semantic_check.rb', line 22 def self.get_component_key_name(component_name) return "LIMNAMEBAG" if /LIMITATION/i.match?(component_name) return "PRODNO" if /PRODUCT/i.match?(component_name) return "GTIN" if /ITEM/i.match?(component_name) raise "Cannot determine keyname for component #{component_name}" end |
Instance Method Details
#get_items(component_name) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/oddb2xml/semantic_check.rb', line 29 def get_items(component_name) # hack to make it spec/check_artikelstamm.rb work if called alone or as part # of the whole spec suite xx = @hash[:ARTIKELSTAMM] || @hash["ARTIKELSTAMM"] comps = xx[component_name.to_sym] || xx[component_name] comps.values.first end |
#load_file(name) ⇒ Object
37 38 39 40 |
# File 'lib/oddb2xml/semantic_check.rb', line 37 def load_file(name) Oddb2xml. "Reading #{name} #{(File.size(name) / 1024 / 1024).to_i} MB. This may take some time" Ox.load(IO.read(name), mode: :hash_no_attrs) end |