Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/lsl/junk.rb,
lib/lsl/ext/ext.rb,
lib/lsl/ext/ext.rb,
lib/lsl/ext/ext.rb,
lib/lsl/ext/ext.rb,
lib/lsl/command/execution.rb
Instance Method Summary collapse
- #array_aware_each(&b) ⇒ Object
- #blank? ⇒ Boolean
- #dsl_method(meth, ops = {}) ⇒ Object
- #dsl_method_arr(meth, ops = {}, &obj_blk) ⇒ Object
- #find_child_node2x(node) ⇒ Object
- #find_child_nodesxx(node) ⇒ Object
- #find_child_nodexx(node) ⇒ Object
- #get_spaced_node(meth) ⇒ Object
- #list_values ⇒ Object
- #present? ⇒ Boolean
- #quoted ⇒ Object
- #quoted? ⇒ Boolean
- #send_if_respond(meth) ⇒ Object
- #send_with_expansion(sym, *args, &b) ⇒ Object
- #unquoted ⇒ Object
Instance Method Details
#array_aware_each(&b) ⇒ Object
17 18 19 |
# File 'lib/lsl/command/execution.rb', line 17 def array_aware_each(&b) [self].flatten.each(&b) end |
#blank? ⇒ Boolean
2 3 4 |
# File 'lib/lsl/ext/ext.rb', line 2 def blank? to_s.strip == '' end |
#dsl_method(meth, ops = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lsl/ext/ext.rb', line 42 def dsl_method(meth,ops={}) define_method(meth) do |*args| if args.size > 0 send("#{meth}=",*args) elsif false && b send("#{meth}=",b) else instance_variable_get("@#{meth}") end end attr_writer meth define_method("#{meth}!") do send("#{meth}=",true) end end |
#dsl_method_arr(meth, ops = {}, &obj_blk) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lsl/ext/ext.rb', line 57 def dsl_method_arr(meth,ops={},&obj_blk) define_method(meth) do |*args| #puts 'start' send("#{meth}=",[]) unless instance_variable_get("@#{meth}") #puts 'start set' if args.size == 1 instance_variable_get("@#{meth}") << args.first elsif args.size == 2 arg = args[1] arg[:name] = args.first instance_variable_get("@#{meth}") << arg elsif false && b instance_variable_get("@#{meth}") << b else res = instance_variable_get("@#{meth}") res = res.map { |x| obj_blk[x,self] } if obj_blk res end end attr_writer meth end |
#find_child_node2x(node) ⇒ Object
22 23 24 |
# File 'lib/lsl/junk.rb', line 22 def find_child_node2x(node) find_child_node(node) end |
#find_child_nodesxx(node) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lsl/junk.rb', line 8 def find_child_nodesxx(node) return [] unless elements res = [] elements.each do |e| #puts e.inspect if $debug and node.to_s == 'single_command' if e.respond_to?(node) res << e.send(node) else res += e.find_child_nodes(node) end end #return send(node) if respond_to?(node) res end |
#find_child_nodexx(node) ⇒ Object
5 6 7 |
# File 'lib/lsl/junk.rb', line 5 def find_child_nodexx(node) find_child_nodes(node).first end |
#get_spaced_node(meth) ⇒ Object
23 24 25 26 |
# File 'lib/lsl/ext/ext.rb', line 23 def get_spaced_node(meth) parent = send("spaced_#{meth}") parent.send_if_respond(meth) end |
#list_values ⇒ Object
2 3 4 |
# File 'lib/lsl/junk.rb', line 2 def list_values elements.map { |x| x.text_value.strip }.map { |x| x.split(" ") }.flatten.map { |x| x.strip }.select { |x| x.present? }.map { |x| x.unquoted } end |
#present? ⇒ Boolean
5 6 7 |
# File 'lib/lsl/ext/ext.rb', line 5 def present? !blank? end |
#quoted ⇒ Object
14 15 16 |
# File 'lib/lsl/ext/ext.rb', line 14 def quoted quoted? ? self : "\"#{self}\"" end |
#quoted? ⇒ Boolean
8 9 10 |
# File 'lib/lsl/ext/ext.rb', line 8 def quoted? ((self[0..0]+self[-1..-1]) == '""') end |
#send_if_respond(meth) ⇒ Object
20 21 22 |
# File 'lib/lsl/ext/ext.rb', line 20 def send_if_respond(meth) respond_to?(meth) ? send(meth) : nil end |
#send_with_expansion(sym, *args, &b) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lsl/command/execution.rb', line 20 def send_with_expansion(sym,*args,&b) return send(sym,&b) if args.empty? res = [] args.each_with_expansion do |a| res << send(sym,*a,&b) end res = res.select { |x| x.present? } if res.size == 1 res = res.first elsif res.empty? res = nil end res end |
#unquoted ⇒ Object
11 12 13 |
# File 'lib/lsl/ext/ext.rb', line 11 def unquoted quoted? ? self[1..-2] : self end |