Class: Parsley
- Inherits:
-
Object
- Object
- Parsley
- Defined in:
- lib/parsley.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parsley, incl = "") ⇒ Parsley
constructor
A new instance of Parsley.
-
#parse(options = {}) ⇒ Object
Valid options:.
Constructor Details
#initialize(parsley, incl = "") ⇒ Parsley
Returns a new instance of Parsley.
17 18 19 20 21 22 23 24 25 |
# File 'lib/parsley.rb', line 17 def initialize(parsley, incl = "") if(parsley.is_a?(Hash)) parsley = recursive_stringify(parsley).to_json end @@mutex ||= Mutex.new @@mutex.synchronize do @parsley = CParsley.new(parsley, incl) end end |
Class Method Details
.user_agent ⇒ Object
13 14 15 |
# File 'lib/parsley.rb', line 13 def self.user_agent @user_agent end |
.user_agent=(agent) ⇒ Object
8 9 10 11 |
# File 'lib/parsley.rb', line 8 def self.user_agent=(agent) @user_agent = agent CParsley.set_user_agent(agent.to_s) end |
Instance Method Details
#parse(options = {}) ⇒ Object
Valid options:
Requires one of: :file – the input file path or url :string – the input string
And optionally (default is the first listed value): :input => [:html, :xml] :output => [:ruby, :json, :xml] :prune => [true, false] :sgwrap => [false, true] :collate => [true, false] :base => “some/base/href” :allow_net => [true, false] :allow_local => [true, false]
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/parsley.rb', line 42 def parse( = {}) [:file] || [:string] || (raise ParsleyError.new("must specify what to parse")) [:sgwrap] = !![:sgwrap] [:is_file] = !![:file] [:has_base] = !![:base] [:base] = [:base].to_s [:file] = [:file].to_s [:string] = [:string].to_s [:input] ||= :html [:output] ||= :ruby [:collate] = true unless .has_key?(:collate) [:prune] = true unless .has_key?(:prune) [:allow_net] = true unless .has_key?(:allow_net) [:allow_local] = true unless .has_key?(:allow_local) [:collate] = !![:collate] [:prune] = !![:prune] [:allow_net] = !![:allow_net] [:allow_local] = !![:allow_local] @parsley.parse() end |