Class: NcsNavigator::Warehouse::TableModeler
- Inherits:
-
Object
- Object
- NcsNavigator::Warehouse::TableModeler
- Defined in:
- lib/ncs_navigator/warehouse/table_modeler.rb
Constant Summary collapse
- VERSION_CHAR_TO_MODULE_NAME_PART =
{ '.' => 'Point' }.merge( Hash[(0..9).to_a.collect(&:to_s).zip(%w(Zero One Two Three Four Five Six Seven Eight Nine))] )
Instance Attribute Summary collapse
-
#mdes_specification_version ⇒ Object
readonly
Returns the value of attribute mdes_specification_version.
-
#mdes_version ⇒ Object
readonly
Returns the value of attribute mdes_version.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Class Method Summary collapse
- .for_version(version_string, options = {}) ⇒ Object
-
.version_module_name(version_string) ⇒ String
The name of the module to use or create for the given version.
Instance Method Summary collapse
- #generate! ⇒ Object
-
#initialize(tables, version_string, specification_version_string, options = {}) ⇒ TableModeler
constructor
A new instance of TableModeler.
- #load! ⇒ Object
- #model! ⇒ Object
Constructor Details
#initialize(tables, version_string, specification_version_string, options = {}) ⇒ TableModeler
Returns a new instance of TableModeler.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 16 def initialize(tables, version_string, specification_version_string, ={}) @tables = tables @mdes_version = version_string @mdes_specification_version = specification_version_string @module_name = .delete(:module).try(:to_s) or fail 'Please specify a target module' @path = .delete(:path) or fail 'Please specify a path to which to generate the files' @path = File.join(path, module_name.underscore) @generated_files = [] @generated_requires = [] end |
Instance Attribute Details
#mdes_specification_version ⇒ Object (readonly)
Returns the value of attribute mdes_specification_version.
14 15 16 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 14 def mdes_specification_version @mdes_specification_version end |
#mdes_version ⇒ Object (readonly)
Returns the value of attribute mdes_version.
13 14 15 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 13 def mdes_version @mdes_version end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
11 12 13 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 11 def module_name @module_name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 10 def path @path end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
12 13 14 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 12 def tables @tables end |
Class Method Details
.for_version(version_string, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 28 def for_version(version_string, ={}) mdes = NcsNavigator::Mdes(version_string) module_name = [self.name.split('::')[0..-2], 'Models', version_module_name(version_string)]. flatten.join('::') TableModeler.new(mdes.transmission_tables, version_string, mdes.specification_version, :module => module_name, :path => [:path]) end |
.version_module_name(version_string) ⇒ String
Returns the name of the module to use or create for the given version.
45 46 47 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 45 def version_module_name(version_string) version_string.split('').collect { |c| VERSION_CHAR_TO_MODULE_NAME_PART[c] }.join('') end |
Instance Method Details
#generate! ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 60 def generate! FileUtils.mkdir_p path generate_models! generate_main_library_file! end |
#load! ⇒ Object
55 56 57 58 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 55 def load! generate! @generated_files.each { |f| load f } end |
#model! ⇒ Object
50 51 52 53 |
# File 'lib/ncs_navigator/warehouse/table_modeler.rb', line 50 def model! load! ::DataMapper.finalize end |