fix_protocol_tools 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/fix_protocol_tools/messages_processor.rb +7 -3
- data/lib/fix_protocol_tools/runner.rb +22 -17
- data/lib/fix_protocol_tools/specification/{fix_specification.rb → dictionary.rb} +3 -5
- data/lib/fix_protocol_tools/specification/{specification_reader.rb → reader.rb} +8 -3
- data/lib/fix_protocol_tools/version.rb +1 -1
- metadata +4 -4
| @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            require 'term/ansicolor'
         | 
| 2 2 | 
             
            require 'logger'
         | 
| 3 | 
            -
            require 'fix_protocol_tools/specification/ | 
| 3 | 
            +
            require 'fix_protocol_tools/specification/dictionary'
         | 
| 4 4 |  | 
| 5 5 | 
             
            module FixProtocolTools
         | 
| 6 6 | 
             
              class MessagesProcessor
         | 
| @@ -12,6 +12,10 @@ module FixProtocolTools | |
| 12 12 | 
             
                  @is_even_line = true
         | 
| 13 13 | 
             
                  @output = init_output_chanel options
         | 
| 14 14 | 
             
                  @grep = options[:grep]
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  if options[:dictionary]
         | 
| 17 | 
            +
                    @spec = Specification::Dictionary.new(Specification::Reader.read_file(options[:dictionary]))
         | 
| 18 | 
            +
                  end
         | 
| 15 19 | 
             
                end
         | 
| 16 20 |  | 
| 17 21 | 
             
                def process()
         | 
| @@ -72,7 +76,7 @@ module FixProtocolTools | |
| 72 76 | 
             
                    rows << formatted_row(field_id, value_id, field_name, value_name, field_name_padding)
         | 
| 73 77 | 
             
                  end
         | 
| 74 78 |  | 
| 75 | 
            -
                  rows.each { |row| @output.puts | 
| 79 | 
            +
                  rows.each { |row| @output.puts(row) } if is_found
         | 
| 76 80 | 
             
                end
         | 
| 77 81 |  | 
| 78 82 | 
             
                def formatted_row(field_id, value_id, field_name, value_name, field_name_padding)
         | 
| @@ -83,7 +87,7 @@ module FixProtocolTools | |
| 83 87 |  | 
| 84 88 | 
             
                def resolve_specification(fields)
         | 
| 85 89 | 
             
                  fix_version = fields[0].last
         | 
| 86 | 
            -
                  Specification:: | 
| 90 | 
            +
                  Specification::Dictionary.new(Specification::Reader.read_defaults(fix_version))
         | 
| 87 91 | 
             
                end
         | 
| 88 92 |  | 
| 89 93 | 
             
                def fix_message_fields(line)
         | 
| @@ -4,44 +4,49 @@ require 'fix_protocol_tools/messages_processor' | |
| 4 4 |  | 
| 5 5 | 
             
            module FixProtocolTools
         | 
| 6 6 | 
             
              class Runner
         | 
| 7 | 
            -
                 | 
| 7 | 
            +
                DEFAULTS = {
         | 
| 8 | 
            +
                    :color => Term::ANSIColor::coloring = STDOUT.isatty,
         | 
| 9 | 
            +
                    :dictionary => ENV['FPT_DICT']
         | 
| 10 | 
            +
                }
         | 
| 8 11 |  | 
| 12 | 
            +
                def initialize
         | 
| 13 | 
            +
                   @options = DEFAULTS
         | 
| 14 | 
            +
                end
         | 
| 9 15 |  | 
| 10 16 | 
             
                def less!
         | 
| 11 | 
            -
                  options | 
| 17 | 
            +
                  @options.merge!(:less => false)
         | 
| 12 18 | 
             
                  opt_parse = OptionParser.new do |opts|
         | 
| 13 19 | 
             
                    opts.banner = "Usage: fixless [options] [fixlogfile]"
         | 
| 14 20 |  | 
| 15 21 | 
             
                    opts.on('-l', '--[no-]less', 'Use less command for output') do |color|
         | 
| 16 | 
            -
                      options[:less] = color
         | 
| 22 | 
            +
                      @options[:less] = color
         | 
| 17 23 | 
             
                    end
         | 
| 18 24 |  | 
| 19 | 
            -
                     | 
| 25 | 
            +
                    dictionary(opts)
         | 
| 26 | 
            +
                    color(opts)
         | 
| 20 27 | 
             
                    help(opts)
         | 
| 21 | 
            -
                    dictionary(options, opts)
         | 
| 22 28 | 
             
                  end
         | 
| 23 29 |  | 
| 24 30 | 
             
                  opt_parse.parse!
         | 
| 25 31 |  | 
| 26 | 
            -
                  MessagesProcessor.new(options).process
         | 
| 32 | 
            +
                  MessagesProcessor.new(@options).process
         | 
| 27 33 | 
             
                end
         | 
| 28 34 |  | 
| 29 35 | 
             
                def grep!
         | 
| 30 | 
            -
                  options = {:color => @coloring}
         | 
| 31 36 | 
             
                  opt_parse = OptionParser.new do |opts|
         | 
| 32 37 | 
             
                    opts.banner = "Usage: fixgrep -v value [options] [fixlogfile]"
         | 
| 33 38 |  | 
| 34 39 | 
             
                    opts.on('-v', '--v value') do |pattern|
         | 
| 35 | 
            -
                      options[:grep] = pattern
         | 
| 40 | 
            +
                      @options[:grep] = pattern
         | 
| 36 41 | 
             
                    end
         | 
| 37 42 |  | 
| 38 | 
            -
                    dictionary( | 
| 39 | 
            -
                    color( | 
| 43 | 
            +
                    dictionary(opts)
         | 
| 44 | 
            +
                    color(opts)
         | 
| 40 45 | 
             
                    help(opts)
         | 
| 41 46 | 
             
                  end
         | 
| 42 47 |  | 
| 43 48 | 
             
                  opt_parse.parse!
         | 
| 44 | 
            -
                  MessagesProcessor.new(options).process
         | 
| 49 | 
            +
                  MessagesProcessor.new(@options).process
         | 
| 45 50 | 
             
                end
         | 
| 46 51 |  | 
| 47 52 | 
             
                private
         | 
| @@ -53,17 +58,17 @@ module FixProtocolTools | |
| 53 58 | 
             
                  end
         | 
| 54 59 | 
             
                end
         | 
| 55 60 |  | 
| 56 | 
            -
                def color( | 
| 61 | 
            +
                def color(opts)
         | 
| 57 62 | 
             
                  opts.on('-c', '--[no-]color', 'Generate color output') do |color|
         | 
| 58 63 | 
             
                    Term::ANSIColor::coloring = color
         | 
| 59 | 
            -
                    options[:color] = color
         | 
| 64 | 
            +
                    @options[:color] = color
         | 
| 60 65 | 
             
                  end
         | 
| 61 66 | 
             
                end
         | 
| 62 67 |  | 
| 63 | 
            -
                def dictionary( | 
| 64 | 
            -
                   | 
| 65 | 
            -
             | 
| 66 | 
            -
                   | 
| 68 | 
            +
                def dictionary(opts)
         | 
| 69 | 
            +
                  opts.on('-d', '--dictionary PATH_TO_DICTIONARY', 'You can set up FPT_DICT env variable instead') do |dictionary|
         | 
| 70 | 
            +
                    @options[:dictionary] = dictionary
         | 
| 71 | 
            +
                  end
         | 
| 67 72 | 
             
                end
         | 
| 68 73 | 
             
              end
         | 
| 69 74 | 
             
            end
         | 
| @@ -1,12 +1,10 @@ | |
| 1 | 
            -
            require 'fix_protocol_tools/specification/ | 
| 1 | 
            +
            require 'fix_protocol_tools/specification/reader'
         | 
| 2 2 |  | 
| 3 3 | 
             
            module FixProtocolTools::Specification
         | 
| 4 | 
            -
              class  | 
| 4 | 
            +
              class Dictionary
         | 
| 5 5 | 
             
                attr_reader :max_field_length
         | 
| 6 6 |  | 
| 7 | 
            -
                def initialize( | 
| 8 | 
            -
                  reader = Reader.read_specification(fix_version)
         | 
| 9 | 
            -
             | 
| 7 | 
            +
                def initialize(reader)
         | 
| 10 8 | 
             
                  @enums = reader.enums
         | 
| 11 9 | 
             
                  @fields = reader.fields
         | 
| 12 10 | 
             
                  @message_types = reader.message_types
         | 
| @@ -8,10 +8,15 @@ module FixProtocolTools::Specification | |
| 8 8 |  | 
| 9 9 | 
             
                attr_reader :fields, :message_types, :enums, :max_field_length
         | 
| 10 10 |  | 
| 11 | 
            -
                def self. | 
| 11 | 
            +
                def self.read_defaults(fix_version)
         | 
| 12 | 
            +
                  path = File.join(SPECIFICATION_PATH, fix_version.delete('.') + '.xml')
         | 
| 13 | 
            +
                  read_file(path)
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def self.read_file(path)
         | 
| 12 17 | 
             
                  reader = new
         | 
| 13 18 |  | 
| 14 | 
            -
                  File.open( | 
| 19 | 
            +
                  File.open(path, 'r') do |file|
         | 
| 15 20 | 
             
                    REXML::Document.parse_stream(file, reader)
         | 
| 16 21 | 
             
                  end
         | 
| 17 22 |  | 
| @@ -21,7 +26,7 @@ module FixProtocolTools::Specification | |
| 21 26 | 
             
                def initialize
         | 
| 22 27 | 
             
                  @message_types = {}
         | 
| 23 28 | 
             
                  @fields = {}
         | 
| 24 | 
            -
                  @enums = Hash.new { |h, k| | 
| 29 | 
            +
                  @enums = Hash.new { |h, k| h[k] = {} }
         | 
| 25 30 |  | 
| 26 31 | 
             
                  @max_field_length = 0
         | 
| 27 32 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: fix_protocol_tools
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0 | 
| 4 | 
            +
              version: 1.1.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013- | 
| 12 | 
            +
            date: 2013-06-02 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: term-ansicolor
         | 
| @@ -73,8 +73,8 @@ files: | |
| 73 73 | 
             
            - lib/fix_protocol_tools.rb
         | 
| 74 74 | 
             
            - lib/fix_protocol_tools/messages_processor.rb
         | 
| 75 75 | 
             
            - lib/fix_protocol_tools/runner.rb
         | 
| 76 | 
            -
            - lib/fix_protocol_tools/specification/ | 
| 77 | 
            -
            - lib/fix_protocol_tools/specification/ | 
| 76 | 
            +
            - lib/fix_protocol_tools/specification/dictionary.rb
         | 
| 77 | 
            +
            - lib/fix_protocol_tools/specification/reader.rb
         | 
| 78 78 | 
             
            - lib/fix_protocol_tools/specification/xml/FIX40.xml
         | 
| 79 79 | 
             
            - lib/fix_protocol_tools/specification/xml/FIX41.xml
         | 
| 80 80 | 
             
            - lib/fix_protocol_tools/specification/xml/FIX42.xml
         |