Module: Fear::ExtractorApi

Included in:
Fear
Defined in:
lib/fear/extractor_api.rb

Instance Method Summary collapse

Instance Method Details

#[](pattern) ⇒ Extractor::Pattern

Note:

it is not intended to be used by itself, rather then with partial functions

Allows to pattern match and extract matcher variables


10
11
12
# File 'lib/fear/extractor_api.rb', line 10

def [](pattern)
  Extractor::Pattern.new(pattern)
end

#register_extractor(*names, extractor) ⇒ Object

Register extractor for given class

Examples:

register_extractor(Fear::Some, Fear.case(Fear::Some) { |some| some.get }.lift)

register_extractor(User, Fear.case(User) { |user|} [user.id, user.email] , )

registering an alias. Alias should be CamelCased string

register_extractor(Fear::Some, 'Some', Fear.case(Fear::Some) { |some| some.get }.lift)

# no you can extract Fear::Some's using Some alias
m.case(Fear['Some(value : Integer)']) { |value:| value * 2 }

31
32
33
# File 'lib/fear/extractor_api.rb', line 31

def register_extractor(*args)
  Extractor.register_extractor(*args)
end