Module: Jekyll::NotBlank
- Defined in:
- jekyll/_plugins/notblank.rb
Instance Method Summary collapse
- #find_notblank(input, property1, id_property) ⇒ Object
- #find_notblank2(input, property1, property2, id_property) ⇒ Object
- #isblank(input) ⇒ Object
- #isnotblank(input) ⇒ Object
Instance Method Details
#find_notblank(input, property1, id_property) ⇒ Object
41 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 68 69 |
# File 'jekyll/_plugins/notblank.rb', line 41 def find_notblank(input, property1, id_property) # given input collection, return an array of all the unique values # for the given property1 of each object of the input collection # the array returned is an array of "id", "value" hashes # where is "id" is the value of object[id_property] # and "value" is the value of object[property1] # Jekyll.logger.warn "find_notblank1" return input unless input.is_a?(Enumerable) input = input.values if input.is_a?(Hash) # Jekyll.logger.warn "Property1 #{property1} " # input.select { |object| isnotblank(item_property(item_property(object, property1) || {}, property2 )) } values = [] input.map {|object| # Jekyll.logger.warn "Object #{object[id_property]}" subobject = object[property1]; idobject = object[id_property]; if ( isnotblank(subobject)) foundobject = Hash.new foundobject["id"] = idobject foundobject["value"] = subobject values.push(idobject) end } values = values.uniq end |
#find_notblank2(input, property1, property2, id_property) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'jekyll/_plugins/notblank.rb', line 72 def find_notblank2(input, property1, property2, id_property) # given input collection of objects, in which each object has # a subcollection of subobjects at property1 # return an array of all the unique values found at property2 of each subobject # the array returned is an array of "id", "value" hashes # where is "id" is the value of subobject[id_property] # and "value" is the value of subobject[property2] #Jekyll.logger.warn "find_notblank2" return input unless input.is_a?(Enumerable) input = input.values if input.is_a?(Hash) # Jekyll.logger.warn "Property1 #{property1} : Property2 #{property2}" # input.select { |object| isnotblank(item_property(item_property(object, property1) || {}, property2 )) } values = [] input.map {|object| # Jekyll.logger.warn "Object #{object[id_property]}" subobject = object[property1]; if (subobject != nil) subobject = subobject.values if subobject.is_a?(Hash) subobject.map { |sub2object| # Jekyll.logger.warn "sub2Object #{sub2object["name"]}" if ( isnotblank(sub2object[property2])) foundobject = Hash.new foundobject["id"] = sub2object[id_property] foundobject["value"] = sub2object[property2] values.push(foundobject) end } end } values = values.uniq end |
#isblank(input) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'jekyll/_plugins/notblank.rb', line 28 def isblank(input) if (input == nil) return true end if (input.length == 0) return true end if (input.to_s.strip.length == 0) return true end return false end |
#isnotblank(input) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'jekyll/_plugins/notblank.rb', line 18 def isnotblank(input) if (input != nil) if (input.length > 0) if (input.to_s.strip.length > 0) return true end end end return false end |