Skip to content

Commit

Permalink
0.1.3 Refactored to make it more viable to use as a library
Browse files Browse the repository at this point in the history
  • Loading branch information
rberger committed Jan 10, 2018
1 parent 3ee1e59 commit 8353e1a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
17 changes: 15 additions & 2 deletions README.rdoc
Expand Up @@ -23,11 +23,24 @@ If you want to start with the original or another version of the +BOD.json+ or t
+ASIObjectDictionary.xml+ then you can override the defaults with the +-a,
--asi_file+ or +-b, --bod_file+ flags

== GLOBAL OPTIONS
-a, --asi_file=arg - Path to the ASIObjectDictionary XML file (default: /Users/rberger/odrive/IBD Google
Drive/Trike/bike-pi/asi_bod/ASIObjectDictionary.xml)
-b, --bod_file=arg - Path to the BOD JSON file (default: /Users/rberger/odrive/IBD Google
Drive/Trike/bike-pi/asi_bod/BODm.json)
--version - Display the program version
--[no-]address_view - View Address (default: enabled)
--[no-]name_view - View Name (default: enabled)
--[no-]description_view - View Description (default: enabled)
-s, --[no-]scale_view - View Scale
-u, --[no-]units_view - View Units
--help - Show this message

== COMMANDS
find - Find a node in one or both of the dictionaries
help - Shows a list of commands or help for one command
merge - Merge the Description from asi to bod
view - View the data
find - Find a node in one or both of the dictionaries
merge - Merge the Description from asi to bod

== Detailed Command Line Info

Expand Down
2 changes: 1 addition & 1 deletion asi_bod.rdoc
@@ -1,6 +1,6 @@
== asi_bod - Manipulate and view the ASIObjectDictionary.xml and BOD.json files

v0.1.2
v0.1.3

=== Global Options
=== -a|--asi_file arg
Expand Down
15 changes: 12 additions & 3 deletions lib/asi_bod/cli.rb
Expand Up @@ -41,9 +41,10 @@ def main

subcommand_option_handling :normal
arguments :strict
sort_help :manually

desc 'Path to the ASIObjectDictionary XML file'
default_value AsiBod.default_file_path
default_value Asi.default_file_path
flag [:a, :asi_file]

desc 'Path to the BOD JSON file'
Expand Down Expand Up @@ -76,7 +77,11 @@ def main
if options[GPARENT][:json]
puts JSON.pretty_generate asi.hash_data
else
Dict.put_results(asi.hash_data, which_keys(global_options))
Dict.specific_keys_per_node(
asi.hash_data,
which_keys(global_options)) do |address, node|
puts node
end
end
end
end
Expand All @@ -87,7 +92,11 @@ def main
if options[GPARENT][:json]
puts JSON.pretty_generate bod.hash_data
else
Dict.put_results(bod.hash_data, which_keys(global_options))
Dict.specific_keys_per_node(
bod.hash_data,
which_keys(global_options)).each_pair do |address, node|
puts node
end
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions lib/asi_bod/dict.rb
Expand Up @@ -29,9 +29,10 @@ def self.node_line(node, keys)
# with only the keys specified
# @param results [Hash] The subset of a full asi or bod Hash
# @param keys [Array] Optional array of keys to display
def self.put_results(results, keys)
results.each_pair do |address, node|
puts Dict.node_line(node, keys)
# @return [Hash<Symbol>,<Hash>] Hash of Hashes with each hash having specified keys
def self.specific_keys_per_node(dict, keys)
dict.each_with_object({}) do |(key, node), memo|
memo[key] = Dict.node_line(node, keys)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/asi_bod/version.rb
@@ -1,3 +1,3 @@
module AsiBod
VERSION = '0.1.2'
VERSION = '0.1.3'
end

0 comments on commit 8353e1a

Please sign in to comment.