Class: Checked::Strings

Inherits:
Object show all
Defined in:
lib/Checked/Ask/Strings.rb,
lib/Checked/Clean/Strings.rb,
lib/Checked/Demand/Strings.rb

Direct Known Subclasses

File_Paths

Instance Method Summary collapse

Instance Method Details

#check!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/Checked/Demand/Strings.rb', line 7

def check!
  case return!
  when String
    return!
    
  when StringIO
    target.rewind
    return! target.readlines
    target.rewind

    return!
    
  else
    demand false, "...must be a String or StringIO."
  end
  
  return!( return!.strip )
end

#chop_extObject



32
33
34
# File 'lib/Checked/Clean/Strings.rb', line 32

def chop_ext
  return!.sub /\.[^\.]+$/, ''
end

#chop_rbObject



40
41
42
# File 'lib/Checked/Clean/Strings.rb', line 40

def chop_rb
  return!.sub %r!\.rb$!, '' 
end

#chop_slash_rObject



44
45
46
# File 'lib/Checked/Clean/Strings.rb', line 44

def chop_slash_r
  return!.gsub "\r", ''
end

#exclude!(matcher) ⇒ Object



30
31
32
# File 'lib/Checked/Demand/Strings.rb', line 30

def exclude! matcher
  demand !(return![matcher]), "...can't contain #{matcher.inspect}"
end

#file_content!Object



56
57
58
# File 'lib/Checked/Demand/Strings.rb', line 56

def file_content! 
  new_content!
end

#file_names(matcher) ⇒ Object



11
12
13
# File 'lib/Checked/Clean/Strings.rb', line 11

def file_names matcher
  ( return!.split.select { |word| word[matcher] } )
end

#file_names_by_ext(matcher) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/Checked/Clean/Strings.rb', line 15

def file_names_by_ext matcher 
  names = file_names(matcher)
  bases = names.map { |s|
    s.sub(%r!#{matcher}$!, '')
  }

  names.zip bases
end

#file_read!Object



47
48
49
# File 'lib/Checked/Demand/Strings.rb', line 47

def file_read!
  return!.gsub("\r\n", "\n")
end

#hostname!Object



60
61
62
63
# File 'lib/Checked/Demand/Strings.rb', line 60

def hostname!
  invalid = return![ %r!([^\dA-Za-z_-]+)! ]
  demand !invalid, "...has invalid characters: #{$1.inspect}"
end

#include!(matcher) ⇒ Object



26
27
28
# File 'lib/Checked/Demand/Strings.rb', line 26

def include! matcher
  demand return![matcher], "...must contain: #{matcher.inspect}"
end

#matches_only!(matcher) ⇒ Object



34
35
36
37
# File 'lib/Checked/Demand/Strings.rb', line 34

def matches_only! matcher
  invalid = return!.gsub(matcher, '')
  demand invalid.empty?, "...has invalid characters: #{str.inspect}" 
end

#new_content!Object



51
52
53
54
# File 'lib/Checked/Demand/Strings.rb', line 51

def new_content!
  not_empty!   
  file_read!
end

#not_empty!(*args) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/Checked/Demand/Strings.rb', line 39

def not_empty! *args
  if args.empty?
    demand !(return!.strip.empty?), "...can't be empty."
  else
    super
  end
end

#os_stardardObject



48
49
50
# File 'lib/Checked/Clean/Strings.rb', line 48

def os_stardard
  chop_slash_r
end

#ruby_nameObject



36
37
38
# File 'lib/Checked/Clean/Strings.rb', line 36

def ruby_name
  File.basename chop_rb
end

#shellObject



24
25
26
27
28
29
30
# File 'lib/Checked/Clean/Strings.rb', line 24

def shell 
  return!
  .split("\n")
  .map(&:strip)
  .reject { |line| line.empty? }
  .join(' && ')
end

#to_camel_caseObject



64
65
66
# File 'lib/Checked/Clean/Strings.rb', line 64

def to_camel_case
  return!.split('_').map(&:capitalize).join
end

#to_class_nameObject



60
61
62
# File 'lib/Checked/Clean/Strings.rb', line 60

def to_class_name
  return!.split('_').map(&:capitalize).join('_')
end

#to_pluralObject



56
57
58
# File 'lib/Checked/Clean/Strings.rb', line 56

def to_plural
  return!.to_single + 's'
end

#to_singleObject



52
53
54
# File 'lib/Checked/Clean/Strings.rb', line 52

def to_single
  return!.gsub( /s\Z/, '' )
end

#untarObject



5
6
7
8
9
# File 'lib/Checked/Clean/Strings.rb', line 5

def untar
  return!
  .sub(/\.tar\.gz$/, '')
  .sub(/\.tar/, '')
end