Class: Predicated::Predicate

Inherits:
Object
  • Object
show all
Defined in:
lib/predicated/predicate.rb,
lib/predicated/from/xml.rb,
lib/predicated/from/json.rb,
lib/predicated/from/url_part.rb,
lib/predicated/from/callable_object.rb,
lib/predicated/from/ruby_code_string.rb

Overview

marker class

Direct Known Subclasses

Binary, Unary

Defined Under Namespace

Modules: JsonStructToPredicate, NodeToPredicate, TranslateToRubyString Classes: DontKnowWhatToDoWithThisJson, DontKnowWhatToDoWithThisSexpError, DontKnowWhatToDoWithThisXmlTag, SexpToPredicate

Class Method Summary collapse

Class Method Details

.from_callable_object(context_or_callable_object = nil, context = nil, &block) ⇒ Object

hrm



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/predicated/from/callable_object.rb', line 12

def self.from_callable_object(context_or_callable_object=nil, context=nil, &block)
  callable_object = nil
  
  if context_or_callable_object.is_a?(Binding) || context_or_callable_object.nil?
    context = context_or_callable_object
    callable_object = block
  else
    callable_object = context_or_callable_object
  end
  
  context ||= callable_object.binding
  
  from_ruby_code_string(TranslateToRubyString.convert(callable_object), context)
end

.from_json_str(json_str) ⇒ Object



8
9
10
# File 'lib/predicated/from/json.rb', line 8

def self.from_json_str(json_str)
  from_json_struct(JSON.parse(json_str))
end

.from_json_struct(json_struct) ⇒ Object



12
13
14
# File 'lib/predicated/from/json.rb', line 12

def self.from_json_struct(json_struct)
  JsonStructToPredicate.convert(json_struct)
end

.from_ruby_code_string(ruby_predicate_string, context = binding()) ⇒ Object



10
11
12
13
# File 'lib/predicated/from/ruby_code_string.rb', line 10

def self.from_ruby_code_string(ruby_predicate_string, context=binding())
  sexp = RubyParser.new.process(ruby_predicate_string.strip)
  SexpToPredicate.new(context).convert(sexp)
end

.from_url_part(url_part) ⇒ Object



8
9
10
# File 'lib/predicated/from/url_part.rb', line 8

def self.from_url_part(url_part)
  TreetopUrlPartParser.new.parse(url_part).to_predicate
end

.from_xml(xml_str) ⇒ Object



8
9
10
# File 'lib/predicated/from/xml.rb', line 8

def self.from_xml(xml_str)
  NodeToPredicate.convert(Nokogiri::XML(xml_str).root)
end