Class: MoreUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/strings.rb

Class Method Summary collapse

Class Method Details

.flag_lookup(arr) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/utils/strings.rb', line 67

def flag_lookup arr
    arr.each_with_object({}) do |e, acc|
        e = e.gsub('--', '')
        key, val = e.split('=')
        acc[key.to_sym] = val
        acc
    end
end

.gem_versionObject



39
40
41
# File 'lib/utils/strings.rb', line 39

def gem_version
    "0.4.2"
end

.get_args(arr) ⇒ Object



63
64
65
# File 'lib/utils/strings.rb', line 63

def get_args arr
    arr.reject { |e| /--/.match(e) }
end

.get_file_str(path) ⇒ Object



43
44
45
# File 'lib/utils/strings.rb', line 43

def get_file_str path
    File.open(path, 'r:UTF-8', &:read)
end

.get_flags(arr) ⇒ Object



59
60
61
# File 'lib/utils/strings.rb', line 59

def get_flags arr
    arr.select { |e| /--/.match(e) }
end

.rootObject



55
56
57
# File 'lib/utils/strings.rb', line 55

def root
    Dir.pwd
end

.this_dirObject



51
52
53
# File 'lib/utils/strings.rb', line 51

def this_dir
    __dir__
end

.versions(lookup) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/utils/strings.rb', line 23

def versions lookup
    version = nil
    begin
      version = lookup[:version].to_i
    rescue
      version = 0
    end
    
    return version < 5 ? wrong_version_error : version
end

.write_file(path, str) ⇒ Object



47
48
49
# File 'lib/utils/strings.rb', line 47

def write_file path, str
    File.write(path, str)
end

.wrong_version_errorObject



34
35
36
37
# File 'lib/utils/strings.rb', line 34

def wrong_version_error
    puts 'Must provide a version option'
    return false
end