onoma 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Rakefile +11 -9
  4. data/bin/console +3 -3
  5. data/config/locales/arb.yml +6455 -4930
  6. data/config/locales/cmn.yml +7227 -0
  7. data/config/locales/deu.yml +7227 -0
  8. data/config/locales/eng.yml +2073 -534
  9. data/config/locales/fra.yml +2093 -452
  10. data/config/locales/ita.yml +7227 -0
  11. data/config/locales/jpn.yml +6412 -4887
  12. data/config/locales/por.yml +6261 -4736
  13. data/config/locales/spa.yml +6076 -4551
  14. data/db/migrate/20151211114316_add_beta_varieties.xml +1 -1
  15. data/db/migrate/20151211124757_add_allium_schoenoprasum_varieties.xml +2 -2
  16. data/db/migrate/20151211153218_add_zea_mays_varieties.xml +1 -1
  17. data/db/migrate/20151216100708_add_lifter_equipment_variants.xml +1 -1
  18. data/db/migrate/20151223164501_update_organic_fertilizer.xml +4 -0
  19. data/db/migrate/20151223171801_update_indicators.xml +4 -0
  20. data/db/migrate/20160104145418_add_matters.xml +14 -0
  21. data/db/migrate/20160104160843_change_product_nature_variants_drain.xml +4 -0
  22. data/db/migrate/20160105095120_add_plugin_cap_varieties.xml +261 -0
  23. data/db/migrate/20160106095232_add_orchard_plugin_cap_varieties.xml +405 -0
  24. data/db/migrate/20160108142009_add_product_nature_variants_nematicide.xml +6 -0
  25. data/db/migrate/20160113144856_update_prunus_avium_parent.xml +32 -0
  26. data/db/migrate/20160115090243_change_plant_varieties.xml +7 -0
  27. data/db/migrate/20160119115401_add_shipping_note_document.xml +4 -0
  28. data/db/migrate/20160128093149_fixes_invalid_parent.xml +102 -0
  29. data/db/migrate/20160128154202_add_product_natures_protective_canvas.xml +6 -0
  30. data/db/migrate/20160204115942_change_protective_net_nature.xml +4 -0
  31. data/db/migrate/20160204122030_change_cover_implanter_abilities.xml +6 -0
  32. data/db/migrate/20160206163031_simplifies_activity_families.xml +135 -0
  33. data/db/migrate/20160207142352_fix_spelling_mistakes_on_associate_accounts.xml +7 -0
  34. data/db/migrate/20160210124624_fix_invalid_abilities_on_product_natures.xml +5 -0
  35. data/db/migrate/20160224234901_add_seedling_sorting.xml +4 -0
  36. data/db/migrate/20160310145038_add_rhodes_grass.xml +5 -0
  37. data/db/migrate/20160315152217_remove_exchange_natures.xml +4 -0
  38. data/db/migrate/20160402125244_add_some_heavy_equipment.xml +14 -0
  39. data/db/migrate/20160408223901_change_zea_variety.xml +14 -0
  40. data/db/migrate/20160410082230_add_chemical_classifications.xml +486 -0
  41. data/db/migrate/20160425100840_add_product_nature_corn_topper.xml +6 -0
  42. data/db/migrate/20160427115742_add_production_systems.xml +9 -0
  43. data/db/migrate/20160428085808_add_rows_count_indicator.xml +4 -0
  44. data/db/migrate/20160503131928_add_equipment_indicators.xml +34 -0
  45. data/db/migrate/20160503155351_fix_taxes.xml +15 -0
  46. data/db/migrate/20160504143733_add_units.xml +6 -0
  47. data/db/migrate/20160509100749_change_item_corn_topper.xml +4 -0
  48. data/db/migrate/20160516075201_add_plant_analysis.xml +4 -0
  49. data/db/migrate/20160520144901_update_plant_analysis.xml +5 -0
  50. data/db/migrate/20160525073342_update_spreader_trailer_product_nature.xml +4 -0
  51. data/db/migrate/20160526075245_update_spreader_trailer_abilities.xml +4 -0
  52. data/db/migrate/20160526092246_update_product_natures_and_variants_for_vegetables.xml +37 -0
  53. data/db/migrate/20160527090330_update_product_natures_seed.xml +5 -0
  54. data/db/migrate/20160531071525_add_procedure_actions.xml +6 -0
  55. data/db/migrate/20160531094927_add_items_for_pollination_pocedure.xml +9 -0
  56. data/db/migrate/20160605122001_add_worker_register.xml +4 -0
  57. data/db/migrate/20160608075549_update_spatial_reference_systems.xml +5437 -0
  58. data/db/migrate/20160608202134_add_missing_procedure_actions.xml +6 -0
  59. data/db/migrate/20160613154204_add_product_nature_variants_hoe_weeder.xml +6 -0
  60. data/db/migrate/20160615121350_add_pivots_in_nomenclature.xml +11 -0
  61. data/db/migrate/20160615122805_add_daily_average_working_time_indicator_and_lifespan_indicators.xml +6 -0
  62. data/db/migrate/20160617142409_add_items_for_hay_bales.xml +8 -0
  63. data/db/migrate/20160622121241_add_procedure_action_conservation_plowing.xml +4 -0
  64. data/db/migrate/20160624073237_add_musca_varieties.xml +5 -0
  65. data/db/migrate/20160627095008_add_weeding_kit.xml +5 -0
  66. data/db/migrate/20160630075849_update_product_nature_additive.xml +4 -0
  67. data/db/migrate/20160630124401_fix_coop_variants.xml +9 -0
  68. data/db/migrate/20160719094049_add_new_procedure_actions.xml +6 -0
  69. data/db/migrate/20160719100836_add_issue_nature.xml +4 -0
  70. data/db/migrate/20160720144130_update_equipment_varieties.xml +33 -0
  71. data/db/migrate/20160721124220_update_product_natures_varieties.xml +58 -0
  72. data/db/migrate/20160725182008_fix_abilities_on_old_equipment.xml +4 -0
  73. data/db/migrate/20160726173309_rename_equipments_to_equipment.xml +6 -0
  74. data/db/migrate/20160727092830_update_malus_pumila_variety_name.xml +4 -0
  75. data/db/migrate/20160802123639_update_unit_name_for_equipment_product_nature_variants.xml +39 -0
  76. data/db/migrate/20160816083232_add_issue_natures.xml +6 -0
  77. data/db/migrate/20160819082951_Add_plant_varieties.xml +10 -0
  78. data/db/migrate/20160829072846_add_procedure_action.xml +4 -0
  79. data/db/migrate/20160830153251_add_new_varieties.xml +6 -0
  80. data/db/migrate/20160909225801_add_missing_stock_variation_accounts.xml +17 -0
  81. data/db/migrate/20160911091901_update_product_nature_categories.xml +53 -0
  82. data/db/migrate/20160912182501_fix_product_nature_categories.xml +5 -0
  83. data/db/migrate/20160914114043_add_tool_maintaining_support.xml +7 -0
  84. data/db/migrate/20160915143142_add_pest_related_indicators.xml +5 -0
  85. data/db/migrate/20160919210501_add_transportation_actions.xml +4 -0
  86. data/db/migrate/20160928113101_add_missing_general_accounts.xml +108 -0
  87. data/db/migrate/20160930091201_add_missing_tax_natures.xml +17 -0
  88. data/db/migrate/20161017090516_fix_product_nature_categories_stock_movement_account.xml +5 -0
  89. data/db/migrate/20161019133613_add_ednotif_eu_country_code.xml +33 -0
  90. data/db/migrate/20161019145441_add_ednotif_animal_indicators.xml +22 -0
  91. data/db/migrate/20161022103401_add_portuguese_chart_of_account.xml +34 -0
  92. data/db/migrate/20161024115013_add_ednotif_indicators_to_cow_product_natures.xml +7 -0
  93. data/db/migrate/20161030174001_add_missing_cap_2016_varieties.xml +13 -0
  94. data/db/migrate/20161103111303_add_plants_sorting_action.xml +4 -0
  95. data/db/migrate/20161202083820_add_new_plant_varieties.xml +13 -0
  96. data/db/migrate/20161212181852_add_procedure_categories.xml +5 -0
  97. data/db/migrate/20161214093347_add_procedure_actions.xml +10 -0
  98. data/db/migrate/20161219171601_add_missing_vat_accounts.xml +4 -0
  99. data/db/migrate/20161219231801_add_outgoing_payment_report.xml +4 -0
  100. data/db/migrate/20170104161824_add_indicators_for_plant_analysis.xml +6 -0
  101. data/db/migrate/20170201180806_set_animal_group_population_counting_to_unitary.xml +23 -0
  102. data/db/migrate/20170203132125_update_momenclature_for_animal_housing_mulching_procedure.xml +7 -0
  103. data/db/migrate/20170206125311_update_nomenclature_for_animal_housing_disinfection_procedure.xml +5 -0
  104. data/db/migrate/20170206163322_update_disinfectant_product_variant.xml +4 -0
  105. data/db/migrate/20170214125925_clean_cow_indicators.xml +8 -0
  106. data/db/migrate/20170216100144_add_algerian_vat.xml +10 -0
  107. data/db/migrate/20170219210901_add_fixed_asset_registry.xml +4 -0
  108. data/db/migrate/20170220211447_add_procedure_category.xml +4 -0
  109. data/db/migrate/20170220222412_add_procedure_action.xml +4 -0
  110. data/db/migrate/20170221102405_add_milking_robot_in_nomenclature.xml +6 -0
  111. data/db/migrate/20170222113119_add_animal_varieties.xml +29 -0
  112. data/db/migrate/20170306154901_add_missing_outstanding_account.xml +4 -0
  113. data/db/migrate/20170308232701_add_fr_pcga_profit_and_loss.xml +4 -0
  114. data/db/migrate/20170312112401_add_fr_pcga_balance_sheet.xml +4 -0
  115. data/db/migrate/20170312172301_add_fr_pcg82_balance_sheet.xml +5 -0
  116. data/db/migrate/20170320073301_add_journal_entry_sheet.xml +8 -0
  117. data/db/migrate/20170320144338_add_sundry_debtors_and_creditors_usage.xml +4 -0
  118. data/db/migrate/20170322223101_add_loan_registry.xml +4 -0
  119. data/db/migrate/20170324084701_add_fixed_asset_sheet.xml +4 -0
  120. data/db/migrate/20170328144501_add_pnt_loan_accounts.xml +5 -0
  121. data/db/migrate/20170328165900_update_foliar_spray_product_nature.xml +4 -0
  122. data/db/migrate/20170328170000_add_indicator.xml +4 -0
  123. data/db/migrate/20170328170100_update_product_nature_seedling.xml +6 -0
  124. data/db/migrate/20170328170200_add_indicators.xml +4 -0
  125. data/db/migrate/20170328170300_add_indicators2.xml +4 -0
  126. data/db/migrate/20170328170400_update_seedling_product_natures.xml +4 -0
  127. data/db/migrate/20170405135101_add_account_journal_entry_sheet.xml +4 -0
  128. data/db/migrate/20170407214236_add_portuguese_account_config.xml +4 -0
  129. data/db/migrate/20170524094443_add_urtica_variety.xml +5 -0
  130. data/db/migrate/20170614130921_add_varieties.xml +117 -0
  131. data/db/migrate/20170627075545_add_varieties2.xml +37 -0
  132. data/db/migrate/20170627081533_add_pending_deposit_payments_account_number_for_pt_accounting_system.xml +4 -0
  133. data/db/migrate/20170718131724_add_issue_natures.xml +54 -0
  134. data/db/migrate/20170803164344_add_procedure_nature_and_category.xml +5 -0
  135. data/db/reference.xml +7904 -939
  136. data/lib/onoma/database.rb +77 -32
  137. data/lib/onoma/item.rb +74 -24
  138. data/lib/onoma/migration/actions/base.rb +1 -1
  139. data/lib/onoma/migration/actions/item_change.rb +5 -5
  140. data/lib/onoma/migration/actions/item_creation.rb +4 -4
  141. data/lib/onoma/migration/actions/item_merging.rb +5 -1
  142. data/lib/onoma/migration/actions/item_removal.rb +1 -1
  143. data/lib/onoma/migration/actions/nomenclature_change.rb +3 -3
  144. data/lib/onoma/migration/actions/nomenclature_creation.rb +4 -4
  145. data/lib/onoma/migration/actions/nomenclature_removal.rb +3 -3
  146. data/lib/onoma/migration/actions/property_creation.rb +2 -2
  147. data/lib/onoma/migration.rb +114 -3
  148. data/lib/onoma/nomenclature.rb +79 -49
  149. data/lib/onoma/property.rb +14 -14
  150. data/lib/onoma/reference.rb +1 -1
  151. data/lib/onoma/reflection.rb +8 -3
  152. data/lib/onoma/relation.rb +25 -3
  153. data/lib/onoma/version.rb +1 -1
  154. data/lib/onoma.rb +31 -62
  155. data/onoma.gemspec +15 -15
  156. metadata +123 -7
  157. data/lib/onoma/migration/base.rb +0 -45
  158. data/lib/onoma/migrator/reference.rb +0 -77
  159. data/lib/onoma/migrator/translation.rb +0 -30
  160. data/lib/onoma/migrator.rb +0 -3
@@ -2,24 +2,26 @@ module Onoma
2
2
  # This class represents a set of nomenclature like the reference DB
3
3
  class Database
4
4
  attr_accessor :version
5
+ attr_reader :path
5
6
 
6
- def initialize
7
+ def initialize(path)
8
+ @path = Pathname.new(path)
7
9
  @nomenclatures = ActiveSupport::HashWithIndifferentAccess.new
8
10
  @version = 0
9
11
  end
10
12
 
11
- def self.load_file(file)
12
- set = new
13
- f = File.open(file, 'rb')
14
- document = Nokogiri::XML(f) do |config|
15
- config.strict.nonet.noblanks.noent
16
- end
17
- f.close
18
- document.root.children.each do |nomenclature|
19
- set.harvest_nomenclature(nomenclature)
20
- end
21
- set.version = document.root['version'].to_i
22
- set
13
+ def self.open(path)
14
+ db = new(path)
15
+ db.send(:parse_file, path) if path.exist?
16
+ db
17
+ end
18
+
19
+ def write
20
+ File.write(@path, to_xml)
21
+ end
22
+
23
+ def copy(path)
24
+ File.write(path, to_xml)
23
25
  end
24
26
 
25
27
  def nomenclature_names
@@ -34,8 +36,8 @@ module Onoma
34
36
  def [](nomenclature_name)
35
37
  @nomenclatures[nomenclature_name]
36
38
  end
37
- alias_method :find, :[]
38
- alias_method :nomenclature, :[]
39
+ alias find []
40
+ alias nomenclature []
39
41
 
40
42
  # Find item
41
43
  def item(nomenclature_name, item_name)
@@ -51,7 +53,7 @@ module Onoma
51
53
 
52
54
  def find!(name)
53
55
  unless nomenclature = @nomenclatures[name]
54
- fail "Nomenclature #{name} does not exist"
56
+ raise "Nomenclature #{name} does not exist"
55
57
  end
56
58
  nomenclature
57
59
  end
@@ -82,16 +84,20 @@ module Onoma
82
84
  xml.nomenclatures(xmlns: Onoma::XMLNS, version: @version) do
83
85
  @nomenclatures.values.sort.each do |nomenclature|
84
86
  xml.nomenclature(nomenclature.to_xml_attrs) do
85
- xml.properties do
86
- nomenclature.properties.values.sort.each do |property|
87
- xml.property(property.to_xml_attrs)
87
+ if nomenclature.properties.any?
88
+ xml.properties do
89
+ nomenclature.properties.values.sort.each do |property|
90
+ xml.property(property.to_xml_attrs)
91
+ end
88
92
  end
89
- end if nomenclature.properties.any?
90
- xml.items do
91
- nomenclature.items.values.sort { |a, b| a.name <=> b.name }.each do |item|
92
- xml.item(item.to_xml_attrs)
93
+ end
94
+ if nomenclature.items.any?
95
+ xml.items do
96
+ nomenclature.items.values.sort_by(&:name).each do |item|
97
+ xml.item(item.to_xml_attrs)
98
+ end
93
99
  end
94
- end if nomenclature.items.any?
100
+ end
95
101
  end
96
102
  end
97
103
  end
@@ -99,22 +105,42 @@ module Onoma
99
105
  builder.to_xml
100
106
  end
101
107
 
102
- def harvest_nomenclature(element)
103
- nomenclature = Nomenclature.harvest(element, set: self)
104
- @nomenclatures[nomenclature.name] = nomenclature
108
+ def exec_action(action)
109
+ case action.action_name.to_sym
110
+ when :nomenclature_creation
111
+ add_nomenclature(action.name, action.options)
112
+ when :nomenclature_change
113
+ change_nomenclature(action.nomenclature, action.changes)
114
+ when :nomenclature_removal
115
+ remove_nomenclature(action.nomenclature)
116
+ when :property_creation
117
+ add_property(action.nomenclature, action.name, action.type, action.options)
118
+ when :property_change
119
+ add_property(action.nomenclature, action.name, action.changes)
120
+ when :item_creation
121
+ add_item(action.nomenclature, action.name, action.options)
122
+ when :item_change
123
+ change_item(action.nomenclature, action.name, action.changes)
124
+ when :item_merging
125
+ merge_item(action.nomenclature, action.name, action.into)
126
+ when :item_removal
127
+ remove_item(action.nomenclature, action.name)
128
+ else
129
+ raise "Unknown action: #{action.action_name}"
130
+ end
105
131
  end
106
132
 
107
133
  def add_nomenclature(name, options = {})
108
- fail "Nomenclature #{name} already exists" if @nomenclatures[name]
134
+ raise "Nomenclature #{name} already exists" if @nomenclatures[name]
109
135
  options[:set] = self
110
136
  @nomenclatures[name] = Nomenclature.new(name, options)
111
137
  end
112
138
 
113
139
  def move_nomenclature(old_name, new_name)
114
140
  unless @nomenclatures[old_name]
115
- fail "Nomenclature #{old_name} does not exist"
141
+ raise "Nomenclature #{old_name} does not exist"
116
142
  end
117
- fail "Nomenclature #{new_name} already exists" if @nomenclatures[new_name]
143
+ raise "Nomenclature #{new_name} already exists" if @nomenclatures[new_name]
118
144
  @nomenclatures[new_name] = @nomenclatures.delete(old_name)
119
145
  @nomenclatures[new_name]
120
146
  end
@@ -139,11 +165,11 @@ module Onoma
139
165
  end
140
166
 
141
167
  def change_property(_nomenclature_name, _property_name, _updates = {})
142
- fail NotImplementedError
168
+ raise NotImplementedError
143
169
  end
144
170
 
145
171
  def remove_property(_nomenclature_name, _property_name, _options = {})
146
- fail NotImplementedError
172
+ raise NotImplementedError
147
173
  end
148
174
 
149
175
  def add_item(nomenclature_name, item_name, options = {})
@@ -167,5 +193,24 @@ module Onoma
167
193
  nomenclature = find!(nomenclature_name)
168
194
  nomenclature.remove_item(item_name)
169
195
  end
196
+
197
+ protected
198
+
199
+ def harvest_nomenclature(element)
200
+ nomenclature = Nomenclature.harvest(element, set: self)
201
+ @nomenclatures[nomenclature.name] = nomenclature
202
+ end
203
+
204
+ def parse_file(file)
205
+ f = File.open(file, 'rb')
206
+ document = Nokogiri::XML(f) do |config|
207
+ config.strict.nonet.noblanks.noent
208
+ end
209
+ f.close
210
+ document.root.children.each do |nomenclature|
211
+ harvest_nomenclature(nomenclature)
212
+ end
213
+ self.version = document.root.attr('version').to_i
214
+ end
170
215
  end
171
216
  end
data/lib/onoma/item.rb CHANGED
@@ -3,7 +3,7 @@ module Onoma
3
3
  class Item
4
4
  attr_reader :nomenclature, :left, :right, :depth, :aliases, :parent_name
5
5
  attr_accessor :name, :attributes
6
- alias_method :properties, :attributes
6
+ alias properties attributes
7
7
 
8
8
  # New item
9
9
  def initialize(nomenclature, name, options = {})
@@ -18,6 +18,7 @@ module Onoma
18
18
  self.parent = parent
19
19
  end
20
20
  @attributes = ActiveSupport::HashWithIndifferentAccess.new
21
+ @children = Set.new
21
22
  options.each do |k, v|
22
23
  set(k, v)
23
24
  end
@@ -29,6 +30,7 @@ module Onoma
29
30
 
30
31
  def parent=(item)
31
32
  old_parent_name = @parent_name
33
+ old_parent = @parent
32
34
  if item.nil?
33
35
  @parent = nil
34
36
  @parent_name = nil
@@ -37,15 +39,27 @@ module Onoma
37
39
  item = nomenclature.find!(item.to_s)
38
40
  end
39
41
  if item.nomenclature != nomenclature
40
- fail 'Item must come from same nomenclature'
42
+ raise 'Item must come from same nomenclature'
41
43
  end
42
- if item.parents.include?(self) || item == self
43
- fail 'Circular dependency. Item can be parent of itself.'
44
+ if item.parents.any? { |p| self == p } || self == item
45
+ raise 'Circular dependency. Item can be parent of itself.'
44
46
  end
45
47
  @parent = item
46
48
  @parent_name = @parent.name.to_s
47
49
  end
48
- @nomenclature.rebuild_tree! if old_parent_name != @parent_name
50
+ if old_parent_name != @parent_name
51
+ old_parent.delete_child(self) if old_parent
52
+ @parent.add_child(self) if @parent
53
+ @nomenclature.rebuild_tree!
54
+ end
55
+ end
56
+
57
+ def add_child(item)
58
+ @children << item
59
+ end
60
+
61
+ def delete_child(item)
62
+ @children.delete(item)
49
63
  end
50
64
 
51
65
  # Changes parent without rebuilding
@@ -59,7 +73,28 @@ module Onoma
59
73
  end
60
74
 
61
75
  def parent
62
- @parent ||= @nomenclature.find(@parent_name)
76
+ return @parent if @parent
77
+ @parent = find_parent
78
+ @parent.add_child(self) if @parent
79
+ @parent
80
+ end
81
+ alias fetch_parent parent
82
+
83
+ def find_parent
84
+ @nomenclature.find(@parent_name)
85
+ end
86
+
87
+ def degree_of_kinship_with(other)
88
+ other_item = item_for_comparison(other)
89
+ a = self_and_parents.reverse
90
+ b = other_item.self_and_parents.reverse
91
+ return nil if a.first != b.first
92
+ common_lineage = 0
93
+ a.size.times do |index|
94
+ break if a[index].nil? || b[index].nil? || a[index] != b[index]
95
+ common_lineage += 1
96
+ end
97
+ a.size + b.size - 2 * common_lineage
63
98
  end
64
99
 
65
100
  def original_nomenclature_name
@@ -71,11 +106,9 @@ module Onoma
71
106
  def children(options = {})
72
107
  if options[:index].is_a?(FalseClass)
73
108
  if options[:recursively].is_a?(FalseClass)
74
- return nomenclature.list.select do |item|
75
- (item.parent == self)
76
- end
109
+ @children.to_a
77
110
  else
78
- return children(index: false, recursive: false).each_with_object([]) do |item, list|
111
+ children(index: false, recursive: false).each_with_object([]) do |item, list|
79
112
  list << item
80
113
  list += item.children(index: false, recursive: true)
81
114
  list
@@ -83,12 +116,12 @@ module Onoma
83
116
  end
84
117
  else
85
118
  if options[:recursively].is_a?(FalseClass)
86
- return nomenclature.list.select do |item|
119
+ nomenclature.list.select do |item|
87
120
  @left < item.left && item.right < @right && item.depth == @depth + 1
88
121
  end
89
122
  else
90
123
  # @children ||=
91
- return nomenclature.list.select do |item|
124
+ nomenclature.list.select do |item|
92
125
  @left < item.left && item.right < @right
93
126
  end
94
127
  end
@@ -96,7 +129,7 @@ module Onoma
96
129
  end
97
130
 
98
131
  def root
99
- self.parent? ? parent.root : self
132
+ parent? ? parent.root : self
100
133
  end
101
134
 
102
135
  # Returns direct parents from the closest to the farthest
@@ -112,6 +145,12 @@ module Onoma
112
145
  [self] + parents
113
146
  end
114
147
 
148
+ def rise(&block)
149
+ result = yield(self)
150
+ return result if result
151
+ parent ? parent.rise(&block) : nil
152
+ end
153
+
115
154
  # Computes left/right value for nested set
116
155
  # Returns right index
117
156
  def rebuild_tree!
@@ -139,7 +178,9 @@ module Onoma
139
178
  def human_name(options = {})
140
179
  "nomenclatures.#{nomenclature.name}.items.#{name}".t(options.merge(default: ["items.#{name}".to_sym, "enumerize.#{nomenclature.name}.#{name}".to_sym, "labels.#{name}".to_sym, name.humanize]))
141
180
  end
142
- alias_method :humanize, :human_name
181
+ alias humanize human_name
182
+ alias localize human_name
183
+ alias l localize
143
184
 
144
185
  def human_notion_name(notion_name, options = {})
145
186
  "nomenclatures.#{nomenclature.name}.notions.#{notion_name}.#{name}".t(options.merge(default: ["labels.#{name}".to_sym]))
@@ -190,7 +231,7 @@ module Onoma
190
231
  def to_xml_attrs
191
232
  attrs = {}
192
233
  attrs[:name] = name
193
- attrs[:parent] = @parent_name if self.parent?
234
+ attrs[:parent] = @parent_name if parent?
194
235
  properties.each do |pname, pvalue|
195
236
  if p = nomenclature.properties[pname.to_s]
196
237
  if p.type == :decimal
@@ -206,11 +247,12 @@ module Onoma
206
247
 
207
248
  # Returns property value
208
249
  def property(name)
250
+ return @name.to_sym if name == :name
209
251
  property = @nomenclature.properties[name]
210
252
  value = @attributes[name]
211
253
  if property
212
254
  if value.nil? && property.fallbacks
213
- for fallback in property.fallbacks
255
+ property.fallbacks.each do |fallback|
214
256
  value ||= @attributes[fallback]
215
257
  break if value
216
258
  end
@@ -227,11 +269,15 @@ module Onoma
227
269
  ["nomenclatures.#{@nomenclature.name}.item_lists.#{self.name}.#{name}.#{i}".t, i]
228
270
  end
229
271
  elsif property.nomenclature?
230
- return Onoma[property(name)].list.collect do |i|
272
+ target_nomenclature = Onoma.find(property(name).to_sym)
273
+ unless target_nomenclature
274
+ raise "Cannot find nomenclature: for #{property(name).inspect}"
275
+ end
276
+ return target_nomenclature.list.collect do |i|
231
277
  [i.human_name, i.name]
232
278
  end
233
279
  else
234
- fail StandardError, 'Cannot call selection for a non-list property'
280
+ raise StandardError, 'Cannot call selection for a non-list property'
235
281
  end
236
282
  end
237
283
 
@@ -247,12 +293,16 @@ module Onoma
247
293
  end
248
294
 
249
295
  def set(name, value)
250
- fail "Invalid property: #{name.inspect}" if [:name, :parent].include?(name.to_sym)
251
- # TODO: check format
252
- if property = nomenclature.properties[name]
253
- value ||= [] if property.list?
296
+ raise "Invalid property: #{name.inspect}" if %i[name parent].include?(name.to_sym)
297
+ # # TODO: check format
298
+ # if property = nomenclature.properties[name]
299
+ # value ||= [] if property.list?
300
+ # end
301
+ if value.nil?
302
+ @attributes.delete(name)
303
+ else
304
+ @attributes[name] = value
254
305
  end
255
- @attributes[name] = value
256
306
  end
257
307
 
258
308
  private
@@ -264,7 +314,7 @@ module Onoma
264
314
  def item_for_comparison(other)
265
315
  item = nomenclature[other.is_a?(Item) ? other.name : other]
266
316
  unless item
267
- fail StandardError, "Invalid operand to compare: #{other.inspect} not in #{nomenclature.name}"
317
+ raise StandardError, "Invalid operand to compare: #{other.inspect} not in #{nomenclature.name}"
268
318
  end
269
319
  item
270
320
  end
@@ -1,5 +1,5 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class Base
5
5
  def self.action_name
@@ -1,5 +1,5 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class ItemChange < Onoma::Migration::Actions::Base
5
5
  attr_reader :nomenclature, :name, :changes
@@ -8,9 +8,9 @@ module Onoma
8
8
  @nomenclature = name.first
9
9
  @name = name.second
10
10
  @changes = element.attributes.delete_if do |k, _v|
11
- %w(item).include?(k)
11
+ %w[item].include?(k)
12
12
  end.each_with_object({}) do |(k, v), h|
13
- h[k.to_sym] = v.to_s
13
+ h[k.to_sym] = (v.to_s.blank? ? nil : v.to_s)
14
14
  end
15
15
  end
16
16
 
@@ -23,9 +23,9 @@ module Onoma
23
23
  end
24
24
 
25
25
  def label
26
- "change_item #{@nomenclature}##{@name}(" + changes.simple_print + ")"
26
+ "change_item #{@nomenclature}##{@name}(" + changes.simple_print + ')'
27
27
  end
28
-
28
+
29
29
  def human_name
30
30
  "Change item #{@nomenclature}##{@name} with " + changes.inspect
31
31
  end
@@ -1,15 +1,15 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class ItemCreation < Onoma::Migration::Actions::Base
5
5
  attr_reader :nomenclature, :name, :options
6
6
  def initialize(element)
7
- fail 'Need item attribute' unless element['item']
7
+ raise 'Need item attribute' unless element['item']
8
8
  name = element['item'].split('#')
9
9
  @nomenclature = name.first
10
10
  @name = name.second
11
11
  @options = element.attributes.delete_if do |k, _v|
12
- k =~ /name(:[a-z]{3})?/ || %w(item parent nomenclature).include?(k)
12
+ k =~ /name(:[a-z]{3})?/ || %w[item parent nomenclature].include?(k)
13
13
  end.each_with_object({}) do |(k, v), h|
14
14
  h[k.to_sym] = v.to_s
15
15
  end
@@ -23,7 +23,7 @@ module Onoma
23
23
  def label
24
24
  "create_item #{@nomenclature}##{@name}" + (@options.any? ? "(#{@options.simple_print})" : '')
25
25
  end
26
-
26
+
27
27
  def human_name
28
28
  updates = []
29
29
  updates << "#{@name} as name"
@@ -1,5 +1,5 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class ItemMerging < Onoma::Migration::Actions::Base
5
5
  attr_reader :nomenclature, :name, :into
@@ -10,6 +10,10 @@ module Onoma
10
10
  @into = element['into'].to_s
11
11
  end
12
12
 
13
+ def label
14
+ "merge_item #{@nomenclature}##{@name} into " + @into.to_s
15
+ end
16
+
13
17
  def human_name
14
18
  "Merge item #{@nomenclature}##{@name} into #{@into}"
15
19
  end
@@ -1,5 +1,5 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class ItemRemoval < Onoma::Migration::Actions::Base
5
5
  attr_reader :nomenclature, :name
@@ -1,11 +1,11 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class NomenclatureChange < Onoma::Migration::Actions::Base
5
5
  attr_reader :nomenclature, :changes
6
6
 
7
7
  def initialize(element)
8
- fail 'No given name' unless element.key?('nomenclature')
8
+ raise 'No given name' unless element.key?('nomenclature')
9
9
  @nomenclature = element['nomenclature'].to_s
10
10
  @changes = {}
11
11
  @changes[:name] = element['name'].to_s if element.key?('name')
@@ -13,7 +13,7 @@ module Onoma
13
13
  @changes[:notions] = element.attr('notions').to_s.split(/\s*\,\s*/).map(&:to_sym)
14
14
  end
15
15
  if element.key?('translateable')
16
- @changes[:translateable] = !(element.attr('translateable').to_s == 'false')
16
+ @changes[:translateable] = element.attr('translateable').to_s != 'false'
17
17
  end
18
18
  end
19
19
 
@@ -1,19 +1,19 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class NomenclatureCreation < Onoma::Migration::Actions::Base
5
5
  attr_reader :nomenclature, :options
6
6
 
7
7
  def initialize(element)
8
8
  @nomenclature = element.key?('nomenclature') ? element['nomenclature'].to_s : element.key?('name') ? element['name'].to_s : nil
9
- fail 'No given name' unless @nomenclature
9
+ raise 'No given name' unless @nomenclature
10
10
  @options = {}
11
11
  notions = element.attr('notions').to_s.split(/\s*\,\s*/).map(&:to_sym)
12
12
  @options[:notions] = notions if notions.any?
13
- @options[:translateable] = !(element.attr('translateable').to_s == 'false')
13
+ @options[:translateable] = element.attr('translateable').to_s != 'false'
14
14
  end
15
15
 
16
- alias_method :name, :nomenclature
16
+ alias name nomenclature
17
17
 
18
18
  def human_name
19
19
  "Create nomenclature #{@name}"
@@ -1,15 +1,15 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class NomenclatureRemoval < Onoma::Migration::Actions::Base
5
5
  attr_reader :nomenclature
6
6
 
7
7
  def initialize(element)
8
8
  @nomenclature = element['nomenclature']
9
- fail 'No given nomenclature' if @nomenclature.blank?
9
+ raise 'No given nomenclature' if @nomenclature.blank?
10
10
  end
11
11
 
12
- alias_method :name, :nomenclature
12
+ alias name nomenclature
13
13
 
14
14
  def label
15
15
  "remove_nomenclature #{@name}"
@@ -1,5 +1,5 @@
1
1
  module Onoma
2
- module Migration
2
+ class Migration
3
3
  module Actions
4
4
  class PropertyCreation < Onoma::Migration::Actions::Base
5
5
  attr_reader :nomenclature, :name, :type, :options
@@ -9,7 +9,7 @@ module Onoma
9
9
  @name = name.second
10
10
  @type = element['type'].to_sym
11
11
  unless Property::TYPES.include?(@type)
12
- fail ArgumentError, "Property #{name} type is unknown: #{@type.inspect}"
12
+ raise ArgumentError, "Property #{name} type is unknown: #{@type.inspect}"
13
13
  end
14
14
  @options = {}
15
15
  if element.has_attribute?('fallbacks')