Module: Littlestitious

Defined in:
lib/littlestitious.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/littlestitious.rb', line 4

def self.included(base)

  base.instance_eval do
    extend(ClassMethods)

    initialize_littlestitious_vars(base)
  end

end

Instance Method Details

#boring?Boolean

Returns:

  • (Boolean)


183
184
185
186
187
188
189
190
191
# File 'lib/littlestitious.rb', line 183

def boring?
  # Matches ascii character 10 and 32 to 126
  # (newline + space + all visible)
  regex_string = '[^\n -~]'.freeze

  @boring_regex ||= Regexp.new regex_string

  @boring_regex.match(self).nil?
end

#includes_non_printing_characters?Boolean

Returns:

  • (Boolean)


173
174
175
176
177
178
179
180
181
# File 'lib/littlestitious.rb', line 173

def includes_non_printing_characters?
  return false if self.boring?

  self.class.non_printing_chars.each do | char_type, char |
    return true if self.include? char
  end

  false
end

#includes_weird_spaces?Boolean

Returns:

  • (Boolean)


163
164
165
166
167
168
169
170
171
# File 'lib/littlestitious.rb', line 163

def includes_weird_spaces?
  return false if self.boring?

  self.class.weird_space_chars.each do | char_type, char |
    return true if self.include? char
  end

  false
end

#includes_zero_width_characters?Boolean

Returns:

  • (Boolean)


153
154
155
156
157
158
159
160
161
# File 'lib/littlestitious.rb', line 153

def includes_zero_width_characters?
  return false if self.boring?

  self.class.zero_width_chars.each do | char_type, char |
    return true if self.include? char
  end

  false
end

#strange_character_countObject Also known as: count_strange_characters, count_strange_chars, count_strange, strange_count, strange_char_count



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/littlestitious.rb', line 193

def strange_character_count

  char_count = Hash.new(0)

  return char_count if self.boring?

  self.each_char do |char|
    char_type = self.class.char_lookup[char]
    next unless char_type
    char_count[char_type] += 1
  end

  char_count

end