Class: Interscript::Command
- Inherits:
-
Thor
- Object
- Thor
- Interscript::Command
- Defined in:
- lib/interscript/command.rb
Overview
Command line interface
Instance Method Summary collapse
- #list ⇒ Object
- #stats ⇒ Object
-
#translit(input) ⇒ Object
Was this option really well thought out? The last parameter is a cache, isn’t it? option :map, aliases: ‘-m’, required: false, default: “{}”, desc: ‘Transliteration mapping json’.
Instance Method Details
#list ⇒ Object
23 24 25 26 27 |
# File 'lib/interscript/command.rb', line 23 def list Interscript.maps(load_path: true).each do |path| puts path end end |
#stats ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/interscript/command.rb', line 30 def stats maps = Interscript.maps(load_path: true) parsed_maps = maps.map { |i| [i, Interscript.parse(i)] }.to_h maps_by_rule_count = parsed_maps.transform_values do |map| map.stages.values.map { |i| i.children.map { |j| j.is_a?(Interscript::Node::Group) ? j.children : j } }.flatten.count end , languages, source_scripts, target_scripts = 4.times.map do |i| maps.group_by { |map| map.split('-')[i] } end puts <<~END Languages supported: #{languages.keys.count} Source scripts supported: #{source_scripts.keys.count} Target scripts supported: #{target_scripts.keys.count} Authorities supported: #{.keys.count} Total number of rules in Interscript: #{maps_by_rule_count.values.sum} END .each do |auth, auth_maps| rule_counts = auth_maps.map { |i| maps_by_rule_count[i] } puts <<~END Authority #{auth}: * Conversion systems: #{auth_maps.count} * Total number of rules: #{rule_counts.sum} END end puts <<~END Interesting facts: * #{maps_by_rule_count.max_by { |i| i.last }.first} has the most rules * Authority #{.max_by { |i| i.last.count }.first} has the most systems * Language #{languages.max_by { |i| i.last.count }.first} has the most systems * Source script #{source_scripts.max_by { |i| i.last.count }.first} has the most systems * Target script #{target_scripts.max_by { |i| i.last.count }.first} has the most systems END end |
#translit(input) ⇒ Object
Was this option really well thought out? The last parameter is a cache, isn’t it? option :map, aliases: ‘-m’, required: false, default: “{}”, desc: ‘Transliteration mapping json’
14 15 16 17 18 19 20 |
# File 'lib/interscript/command.rb', line 14 def translit(input) if [:output] Interscript.transliterate_file([:system], input, [:output]) #, JSON.parse(options[:map])) else puts Interscript.transliterate([:system], IO.read(input)) end end |