Module: Nomen

Defined in:
lib/nomen.rb,
lib/nomen/item.rb,
lib/nomen/record.rb,
lib/nomen/migrator.rb,
lib/nomen/relation.rb,
lib/nomen/migration.rb,
lib/nomen/reference.rb,
app/models/nomen/sex.rb,
app/models/nomen/tax.rb,
lib/nomen/reflection.rb,
app/models/nomen/land.rb,
app/models/nomen/role.rb,
app/models/nomen/unit.rb,
lib/nomen/nomenclature.rb,
app/models/nomen/figure.rb,
app/models/nomen/ability.rb,
app/models/nomen/account.rb,
app/models/nomen/country.rb,
app/models/nomen/variety.rb,
lib/nomen/migration/base.rb,
lib/nomen/migrator/model.rb,
app/models/nomen/crop_set.rb,
app/models/nomen/currency.rb,
app/models/nomen/language.rb,
app/models/nomen/molecule.rb,
lib/nomen/property_nature.rb,
app/models/nomen/dimension.rb,
app/models/nomen/indicator.rb,
lib/nomen/nomenclature_set.rb,
app/models/nomen/tax_nature.rb,
lib/nomen/migration/actions.rb,
app/models/nomen/net_service.rb,
app/models/nomen/soil_nature.rb,
app/models/nomen/working_set.rb,
lib/nomen/migrator/reference.rb,
app/models/nomen/event_nature.rb,
app/models/nomen/guide_nature.rb,
app/models/nomen/issue_nature.rb,
app/models/nomen/running_cost.rb,
app/models/nomen/certification.rb,
app/models/nomen/delivery_mode.rb,
lib/nomen/migrator/translation.rb,
app/models/nomen/procedure_role.rb,
app/models/nomen/product_nature.rb,
app/models/nomen/activity_family.rb,
app/models/nomen/analysis_nature.rb,
app/models/nomen/document_nature.rb,
app/models/nomen/fence_perimeter.rb,
lib/nomen/migration/actions/base.rb,
app/models/nomen/chemical_element.rb,
app/models/nomen/plant_life_state.rb,
app/models/nomen/procedure_action.rb,
app/models/nomen/procedure_nature.rb,
app/models/nomen/production_usage.rb,
app/models/nomen/accounting_system.rb,
app/models/nomen/animal_life_state.rb,
app/models/nomen/document_category.rb,
app/models/nomen/identifier_nature.rb,
app/models/nomen/production_nature.rb,
app/models/nomen/production_system.rb,
app/models/nomen/entity_link_nature.rb,
app/models/nomen/opportunity_origin.rb,
app/models/nomen/procedure_category.rb,
app/models/nomen/administrative_area.rb,
app/models/nomen/certification_label.rb,
app/models/nomen/plants_growth_level.rb,
app/models/nomen/soil_cultural_state.rb,
app/models/nomen/product_nature_variant.rb,
lib/nomen/migration/actions/item_change.rb,
app/models/nomen/chemical_classification.rb,
app/models/nomen/product_nature_category.rb,
lib/nomen/migration/actions/item_merging.rb,
lib/nomen/migration/actions/item_removal.rb,
app/models/nomen/mammalia_birth_condition.rb,
app/models/nomen/plant_reproduction_state.rb,
app/models/nomen/spatial_reference_system.rb,
lib/nomen/migration/actions/item_creation.rb,
app/models/nomen/administrative_area_nature.rb,
app/models/nomen/phosphorus_analysis_method.rb,
app/models/nomen/residue_elimination_method.rb,
app/models/nomen/mammalia_reproduction_state.rb,
lib/nomen/migration/actions/property_creation.rb,
lib/nomen/migration/actions/nomenclature_change.rb,
lib/nomen/migration/actions/nomenclature_removal.rb,
lib/nomen/migration/actions/nomenclature_creation.rb,
app/models/nomen/cation_exchange_capacity_analysis_method.rb

Defined Under Namespace

Modules: Migration, Migrator, Record Classes: Ability, Account, AccountingSystem, ActivityFamily, AdministrativeArea, AdministrativeAreaNature, AnalysisNature, AnimalLifeState, CationExchangeCapacityAnalysisMethod, Certification, CertificationLabel, ChemicalClassification, ChemicalElement, Country, CropSet, Currency, DeliveryMode, Dimension, DocumentCategory, DocumentNature, EntityLinkNature, Error, EventNature, FencePerimeter, Figure, GuideNature, IdentifierNature, Indicator, InvalidProperty, InvalidPropertyNature, IssueNature, Item, ItemNotFound, Land, Language, MammaliaBirthCondition, MammaliaReproductionState, MissingChoices, MissingNomenclature, Molecule, NetService, Nomenclature, NomenclatureSet, OpportunityOrigin, PhosphorusAnalysisMethod, PlantLifeState, PlantReproductionState, PlantsGrowthLevel, ProcedureAction, ProcedureCategory, ProcedureNature, ProcedureRole, ProductNature, ProductNatureCategory, ProductNatureVariant, ProductionNature, ProductionSystem, ProductionUsage, PropertyNature, Reference, Reflection, Relation, ResidueEliminationMethod, Role, RunningCost, Sex, SoilCulturalState, SoilNature, SpatialReferenceSystem, Tax, TaxNature, Unit, Variety, WorkingSet

Constant Summary collapse

XMLNS =
'http://www.ekylibre.org/XML/2013/nomenclatures'.freeze
NS_SEPARATOR =
'-'.freeze
PROPERTY_TYPES =
%i[boolean item item_list choice choice_list string_list date decimal integer nomenclature string symbol].freeze

Class Method Summary collapse

Class Method Details

.allObject


84
85
86
# File 'lib/nomen.rb', line 84

def all
  set.nomenclatures
end

.each(&block) ⇒ Object

Browse all nomenclatures


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

def each(&block)
  set.each(&block)
end

.find(*args) ⇒ Object

Give access to named nomenclatures


92
93
94
95
96
97
98
99
100
101
102
# File 'lib/nomen.rb', line 92

def find(*args)
  options = args.extract_options!
  name = args.shift
  nomenclature = find_or_initialize(name)
  if args.empty?
    return nomenclature
  elsif args.size == 1
    return nomenclature.find(args.shift) if nomenclature
  end
  nil
end

.find_or_initialize(name) ⇒ Object


104
105
106
# File 'lib/nomen.rb', line 104

def find_or_initialize(name)
  set[name] || set.load_data_from_xml(name)
end

.load!Object

Force loading of nomenclatures


109
110
111
# File 'lib/nomen.rb', line 109

def load!
  @@set = NomenclatureSet.load_file(reference_path)
end

.migrationsObject

Returns list of Nomen::Migration


65
66
67
68
69
# File 'lib/nomen.rb', line 65

def migrations
  Dir.glob(migrations_path.join('*.xml')).sort.collect do |f|
    Nomen::Migration::Base.parse(Pathname.new(f))
  end
end

.migrations_pathObject


39
40
41
# File 'lib/nomen.rb', line 39

def migrations_path
  root_path.join('migrate')
end

.missing_migrationsObject

Returns list of migrations since last done


72
73
74
75
76
77
# File 'lib/nomen.rb', line 72

def missing_migrations
  last_version = reference_version
  migrations.select do |m|
    m.number > last_version
  end
end

.namesObject

Returns the names of the nomenclatures


80
81
82
# File 'lib/nomen.rb', line 80

def names
  set.nomenclature_names
end

.reference_documentObject


53
54
55
56
57
58
59
60
61
62
# File 'lib/nomen.rb', line 53

def reference_document
  unless @document
    f = File.open(reference_path, 'rb')
    @document = Nokogiri::XML(f) do |config|
      config.strict.nonet.noblanks.noent
    end
    f.close
  end
  @document
end

.reference_pathObject


43
44
45
# File 'lib/nomen.rb', line 43

def reference_path
  root_path.join('db.xml')
end

.reference_versionObject

Returns version of DB


48
49
50
51
# File 'lib/nomen.rb', line 48

def reference_version
  return 0 unless reference_path.exist?
  reference_document.root['version'].to_i
end

.root_pathObject


35
36
37
# File 'lib/nomen.rb', line 35

def root_path
  Rails.root.join('db', 'nomenclatures')
end

.setObject


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

def set
  @@set ||= NomenclatureSet.new
end