Sha256: 2c223852363af4750d3c9dc28ea19282a346e5062a2081e84a8bcbb65cbba27d

Contents?: true

Size: 676 Bytes

Versions: 3

Compression:

Stored size: 676 Bytes

Contents

module HackTree
  module Parser
    # Base class for parsers. Parsers generally process text into collection(s).
    class Base
      def initialize(attrs = {})
        attrs.each {|k, v| send("#{k}=", v)}
      end

      # Synonym of #process.
      def [](content)
        process(content)
      end

      def process(content)
        # NOTE: In parser meaning "content" argument name looks more solid. For mapper "data" is more appropriate. Both are okay for their cases.
        raise "Redefine `process` in your class (#{self.class})"
      end

      private

      def require_attr(attr)
        send(attr) or raise "`#{attr}` is not set"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hack_tree-0.1.2 lib/hack_tree/parser/base.rb
hack_tree-0.1.1 lib/hack_tree/parser/base.rb
hack_tree-0.1.0 lib/hack_tree/parser/base.rb