Class: BuildingSync::WorkflowMakerBase
- Inherits:
-
Object
- Object
- BuildingSync::WorkflowMakerBase
- Defined in:
- lib/buildingsync/makers/workflow_maker_base.rb
Overview
base class for objects that will configure workflows based on building sync files
Direct Known Subclasses
Instance Method Summary collapse
-
#add_measure_path(measures_dir) ⇒ Boolean
add measure path.
-
#add_new_measure(workflow, measure_dir_name) ⇒ Boolean
Adds a new measure to the workflow ONLY if it doesn't already exist.
-
#clear_all_measures ⇒ Object
clear all measures from the list in the workflow.
- #get_prefix ⇒ Object
-
#initialize(doc, ns) ⇒ WorkflowMakerBase
constructor
initialize.
-
#save_xml(filename) ⇒ Object
TODO: add a schema validation and re-ordering mechanism for XML elements Format, add declaration, and write xml to disk.
-
#set_measure_argument(workflow, measure_dir_name, argument_name, argument_value) ⇒ Boolean
set measure argument.
-
#set_measure_path(workflow, measures_dir) ⇒ Object
set only one measure path.
-
#set_measure_paths(measures_dir_array) ⇒ Object
set multiple measure paths.
Constructor Details
#initialize(doc, ns) ⇒ WorkflowMakerBase
initialize
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 49 def initialize(doc, ns) if !doc.is_a?(REXML::Document) raise StandardError, "doc must be an REXML::Document. Passed object of class: #{doc.class}" end if !ns.is_a?(String) raise StandardError, "ns must be String. Passed object of class: #{ns.class}" end @doc = doc @ns = ns @workflow = nil end |
Instance Method Details
#add_measure_path(measures_dir) ⇒ Boolean
add measure path
115 116 117 118 119 120 121 122 123 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 115 def add_measure_path(measures_dir) @workflow['measure_paths'].each do |dir| if dir == measures_dir return false end end @workflow['measure_paths'] << measures_dir return true end |
#add_new_measure(workflow, measure_dir_name) ⇒ Boolean
Adds a new measure to the workflow ONLY if it doesn't already exist
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 153 def add_new_measure(workflow, measure_dir_name) # first we check if the measure already exists workflow['steps'].each do |step| if step['measure_dir_name'] == measure_dir_name return false end end # if it does not exist we add it new_step = {} new_step['measure_dir_name'] = measure_dir_name workflow['steps'].unshift(new_step) return true end |
#clear_all_measures ⇒ Object
clear all measures from the list in the workflow
107 108 109 110 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 107 def clear_all_measures @workflow.delete('steps') @workflow['steps'] = [] end |
#get_prefix ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 63 def get_prefix if @ns == '' return '' else return "#{@ns}:" end end |
#save_xml(filename) ⇒ Object
TODO: add a schema validation and re-ordering mechanism for XML elements Format, add declaration, and write xml to disk
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 74 def save_xml(filename) # first we make sure all directories exist FileUtils.mkdir_p(File.dirname(filename)) # Setup formatting formatter = REXML::Formatters::Pretty.new formatter.compact = true # Setup document declaration decl = REXML::XMLDecl.new decl.encoding = REXML::XMLDecl::DEFAULT_ENCODING # UTF-8 @doc << decl # Write file File.open(filename, 'w') do |file| formatter.write(@doc, file) end end |
#set_measure_argument(workflow, measure_dir_name, argument_name, argument_value) ⇒ Boolean
set measure argument
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 132 def set_measure_argument(workflow, measure_dir_name, argument_name, argument_value) result = false workflow['steps'].each do |step| if step['measure_dir_name'] == measure_dir_name step['arguments'][argument_name] = argument_value result = true end end if !result raise "Could not set '#{argument_name}' to '#{argument_value}' for measure '#{measure_dir_name}'" end return result end |
#set_measure_path(workflow, measures_dir) ⇒ Object
set only one measure path
96 97 98 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 96 def set_measure_path(workflow, measures_dir) workflow['measure_paths'] = [measures_dir] end |
#set_measure_paths(measures_dir_array) ⇒ Object
set multiple measure paths
102 103 104 |
# File 'lib/buildingsync/makers/workflow_maker_base.rb', line 102 def set_measure_paths(measures_dir_array) @workflow['measure_paths'] = measures_dir_array end |