Module: Decanter::Parser

Extended by:
Utils
Defined in:
lib/decanter/parser.rb,
lib/decanter/parser/base.rb,
lib/decanter/parser/core.rb,
lib/decanter/parser/utils.rb,
lib/decanter/parser/date_parser.rb,
lib/decanter/parser/hash_parser.rb,
lib/decanter/parser/pass_parser.rb,
lib/decanter/parser/array_parser.rb,
lib/decanter/parser/float_parser.rb,
lib/decanter/parser/phone_parser.rb,
lib/decanter/parser/value_parser.rb,
lib/decanter/parser/string_parser.rb,
lib/decanter/parser/boolean_parser.rb,
lib/decanter/parser/compose_parser.rb,
lib/decanter/parser/integer_parser.rb,
lib/decanter/parser/datetime_parser.rb

Defined Under Namespace

Modules: Core, Utils Classes: ArrayParser, Base, BooleanParser, ComposeParser, DateParser, DateTimeParser, FloatParser, HashParser, IntegerParser, PassParser, PhoneParser, StringParser, ValueParser

Class Method Summary collapse

Methods included from Utils

camelize_str, concat_str, singular_class_present?, singularize_and_camelize_str, symbol_to_string

Class Method Details

.compose_parsers(parsers) ⇒ Object

Composes multiple parsers into a single parser

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/decanter/parser.rb', line 17

def compose_parsers(parsers)
  raise ArgumentError.new('expects an array') unless parsers.is_a? Array
  composed_parser = Class.new(Decanter::Parser::ComposeParser)
  composed_parser.parsers(parsers)
  composed_parser
end

.parsers_for(klass_or_syms) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/decanter/parser.rb', line 8

def parsers_for(klass_or_syms)
  Array.wrap(klass_or_syms)
       .map { |klass_or_sym| klass_or_sym_to_str(klass_or_sym) }
       .map { |parser_str|   parser_constantize(parser_str) }
       .map { |parser|       expand(parser) }
       .flatten
end