Sha256: 60598f9ea73d98fcfb205a94fe5f78e8184eb847d36a1282b11f201b219a4143

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

module Keepasser
  class Parser < Hash
    attr_reader :path
    
    def initialize path
      @path = path
      lines = File.readlines @path

      bucket= []
      lines.each do |line|
        if line[0..8] == '*** Group'
          @group = line[11..-6]
          self[@group] = {}
        else
          unless line == "\n"
            bucket.push line
          else
            if bucket.any?
              e = Entry.new bucket
              e.group = @group

              self[@group][e.title] = e.clone

              bucket = []
            end
          end
        end
      end
      e = Entry.new bucket
      e.group = @group

      self[@group][e.title] = e.clone
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
keepasser-0.1.0 lib/keepasser/parser.rb