Sha256: 8f1b2e341fba4b1199bb2b2ed091b7916c69306ea54a6f3b20042e14558b91e1
Contents?: true
Size: 750 Bytes
Versions: 1
Compression:
Stored size: 750 Bytes
Contents
module FormatParser # Small DSL to avoid repetitive code while defining a new parsers. Also, it can be leveraged by # third parties to define their own parsers. module DSL def self.included(base) base.extend(ClassMethods) end module ClassMethods def formats(*registred_formats) __define(:formats, registred_formats) end def natures(*registred_natures) __define(:natures, registred_natures) end private def __define(name, value) throw ArgumentError("empty array") if value.empty? throw ArgumentError("requires array of symbols") if value.any? { |s| !s.is_a?(Symbol) } define_method(name) do value end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
format_parser-0.2.0 | lib/parsers/dsl.rb |