Class: Screening::Data
- Inherits:
-
Array
- Object
- Array
- Screening::Data
- Includes:
- ArrayToSelfConvert
- Defined in:
- lib/screening.rb
Instance Attribute Summary collapse
-
#binding_attributes ⇒ Object
Returns the value of attribute binding_attributes.
-
#garbage ⇒ Object
Returns the value of attribute garbage.
Attributes included from ArrayToSelfConvert
Instance Method Summary collapse
- #bind(attributes = []) ⇒ Object
- #classify(grade, target, block) ⇒ Object
- #filter(target, paper) ⇒ Object
- #filter_block(target, block) ⇒ Object
- #filter_moji(target) ⇒ Object
- #omit(target, block) ⇒ Object
- #push_with_statistics(*args) ⇒ Object (also: #push)
- #start {|self.last| ... } ⇒ Object
Methods included from ArrayToSelfConvert
Instance Attribute Details
#binding_attributes ⇒ Object
Returns the value of attribute binding_attributes.
30 31 32 |
# File 'lib/screening.rb', line 30 def binding_attributes @binding_attributes end |
#garbage ⇒ Object
Returns the value of attribute garbage.
30 31 32 |
# File 'lib/screening.rb', line 30 def garbage @garbage end |
Instance Method Details
#bind(attributes = []) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/screening.rb', line 95 def bind(attributes=[]) raise ArgumentError, "Permit only Array." unless attributes.is_a? Array @binding_attributes ||= [] @binding_attributes.concat(attributes).uniq! @binding_attributes end |
#classify(grade, target, block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/screening.rb', line 65 def classify(grade, target, block) self.class.class_eval do attr_accessor grade end self.__send__("#{grade}=", Screening::Data.new) if self.__send__(grade).nil? self.each do |element| if block.call(element.__send__(target)) self.__send__(grade).push(element) end end self.__send__(grade).uniq! # Thinking end |
#filter(target, paper) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/screening.rb', line 42 def filter(target, paper) if paper.is_a? Proc filter_block(target, paper) elsif paper == :moji filter_moji(target) end end |
#filter_block(target, block) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/screening.rb', line 58 def filter_block(target, block) self.each do |element| next if element.__send__(target).blank? res = block.call(element.__send__(target)) element.__send__("#{target}=", res) end end |
#filter_moji(target) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/screening.rb', line 49 def filter_moji(target) self.each do |element| next if element.__send__(target).blank? element.__send__("#{target}=", Moji.zen_to_han(element.__send__(target), Moji::ZEN_ALPHA)) element.__send__("#{target}=", Moji.han_to_zen(element.__send__(target), Moji::HAN_KATA)) element.__send__("#{target}=", Moji.zen_to_han(element.__send__(target), Moji::ZEN_ASYMBOL)) element.__send__("#{target}=", Moji.zen_to_han(element.__send__(target), Moji::ZEN_NUMBER)) end end |
#omit(target, block) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/screening.rb', line 35 def omit(target, block) @garbage ||= [] self.each do |element| @garbage.push(element) if block.call(element.__send__(target)) end self.delete_if {|element| block.call(element.__send__(target))} end |
#push_with_statistics(*args) ⇒ Object Also known as: push
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/screening.rb', line 77 def push_with_statistics(*args) # override args.each do |arg| if arg.is_a? Hash if !@binding_attributes.nil? && @binding_attributes != [] arg.keys.each do |key| raise "#{key} is NOT permitted." unless @binding_attributes.include?(key.to_sym) end end self.push_without_statistics(Screening::Statistics.new.merge!(arg)) else raise "You cannot add elements except Hash(And this Hash is transformed into Screening::Statistics automatically.)." end end return self end |
#start {|self.last| ... } ⇒ Object
31 32 33 34 |
# File 'lib/screening.rb', line 31 def start self.push(Screening::Statistics.new) yield(self.last) end |