usiri 0.0.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6934388e5abf68f138ba459578193e8b853f37a5
4
- data.tar.gz: 7ce2bb0b2f61d72a051493d6c5a003f8ca73753d
3
+ metadata.gz: bffa41986da1febf0093238fbdf6b6e663438a9a
4
+ data.tar.gz: da5bfee35f6fd518106e1be981385ef0e00d502b
5
5
  SHA512:
6
- metadata.gz: dfd606ddee565a08e8087d9716702631cbcd4a88b80bab7a003f637de0d71c6b785d4f67f6a589d62b0da59536f34c47796b253534157a2b75b939dc7c9372d0
7
- data.tar.gz: 9e808955598cd608a72f7bdbc86d1dfc8a45e2a333330b759906d830def4c789b69730337e99134b1527a862c832f4337003b09cb08f323ce19e3c115cda2ba4
6
+ metadata.gz: aae629ee9171f942bcd0575d01fd5f2900e0b8c22aecc8e6c78c548039871d651f21b0fc713c7c84e952cfbc7172c9153b44bd2f396df283f0f53252c681e256
7
+ data.tar.gz: d574af8ea13cd59d7065bd3310f07fc352ff60cfe34d94e43a645335f8b011e5fceacc808cc0223c53b8e51ceea57165c9d6f9f6b0e9101858ec811732ff2243
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rspec", "~> 3.7", :group => [:development]
4
+ gem "inquirer", "~> 0.2.1"
5
+ gem "clipboard", "~> 1.1"
6
+
7
+ # Added at 2017-11-05 21:25:52 +0300 by inn:
8
+ gem "colorize", "~> 0.8.1"
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ clipboard (1.1.1)
5
+ colorize (0.8.1)
6
+ diff-lcs (1.3)
7
+ inquirer (0.2.1)
8
+ term-ansicolor (>= 1.2.2)
9
+ rspec (3.7.0)
10
+ rspec-core (~> 3.7.0)
11
+ rspec-expectations (~> 3.7.0)
12
+ rspec-mocks (~> 3.7.0)
13
+ rspec-core (3.7.0)
14
+ rspec-support (~> 3.7.0)
15
+ rspec-expectations (3.7.0)
16
+ diff-lcs (>= 1.2.0, < 2.0)
17
+ rspec-support (~> 3.7.0)
18
+ rspec-mocks (3.7.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.7.0)
21
+ rspec-support (3.7.0)
22
+ term-ansicolor (1.6.0)
23
+ tins (~> 1.0)
24
+ tins (1.15.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ clipboard (~> 1.1)
31
+ colorize (~> 0.8.1)
32
+ inquirer (~> 0.2.1)
33
+ rspec (~> 3.7)
34
+
35
+ BUNDLED WITH
36
+ 1.15.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Itenga
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ # usiri
File without changes
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
+
5
+ require "usiri"
6
+
7
+ Usiri.tengeneza_siri(ARGV)
@@ -1,9 +1,122 @@
1
- class Usiri
2
- def initialize(argument)
3
- @argument = argument
1
+ require 'digest'
2
+ require 'clipboard'
3
+ require 'usiri/msaidizi'
4
+
5
+
6
+ module Usiri
7
+ extend self
8
+
9
+ def tengeneza_siri(chaguo_cli)
10
+ chaguo = Msaidizi.chambua_chaguo chaguo_cli
11
+ @jina = chaguo.jina
12
+ @siti = chaguo.siti
13
+ @siri = chaguo.siri
14
+ @alama = chaguo.alama
15
+ @urefu = chaguo.urefu
16
+ @toleo = chaguo.toleo
17
+ @id = tengeneza_id
18
+
19
+ tengeneza
20
+ end
21
+
22
+ private
23
+ def tengeneza
24
+ tokeo = hesabu_tokeo
25
+ kutoka = maalama if tumiya_alama?
26
+
27
+ if tumiya_alama? and ina_alama? tokeo
28
+ tokeo = badilisha_maalama tokeo, kutoka, hashi
29
+ elsif tumiya_alama?
30
+ tokeo = ingiza_alama tokeo, kutoka, hashi
31
+ elsif ina_alama? tokeo
32
+ kutoka = ju_chini
33
+ tokeo = badilisha_maalama tokeo, kutoka, hashi
34
+ end
35
+
36
+ copi_ila_ubao tokeo
37
+ end
38
+
39
+ def tengeneza_id
40
+ @jina + @siti + @siri + @alama.to_s + @urefu.to_s + @toleo.to_s
41
+ end
42
+
43
+ def hesabu_tokeo
44
+ Digest::SHA512.base64digest(@id)[0...@urefu]
45
+ end
46
+
47
+ def hashi
48
+ h = 7
49
+ @id.each_char { |chr| h = h*19 + chr.ord }
50
+ h
51
+ end
52
+
53
+ def tumiya_alama?
54
+ @alama != :bila
55
+ end
56
+
57
+ def ina_alama? neno
58
+ neno.match? ALAMA_REGEX
59
+ end
60
+
61
+ def ni_alama? chr
62
+ ina_alama? chr
63
+ end
64
+
65
+ def alama_safi
66
+ "!#$%&*+-<=>?@[]^{}".split ""
67
+ end
68
+
69
+ def alama_yoyote
70
+ [
71
+ (33..47).to_a,
72
+ (58..64).to_a,
73
+ (91..96).to_a,
74
+ (123..126).to_a,
75
+ ].flatten.map { |e| e.chr }
76
+ end
77
+
78
+ def maalama
79
+ @alama == ALAMA_MSINGI ? alama_yoyote : alama_safi
80
+ end
81
+
82
+ def ju_chini
83
+ [
84
+ (65..90).to_a,
85
+ (97..122).to_a,
86
+ ].flatten.map { |e| e.chr }
87
+ end
88
+
89
+ def badilisha_maalama tokeo, kutoka, hashi
90
+ tokeo = tokeo.split("")
91
+ tokeo.each_with_index do |chr, sehemu|
92
+
93
+ if ni_alama? chr
94
+ sehemu_tokeo = ((sehemu + 1) * hashi) % kutoka.length
95
+ alama = kutoka[sehemu_tokeo]
96
+ tokeo[sehemu] = alama
97
+ end
98
+ end
99
+
100
+ tokeo.join("")
101
+ end
102
+
103
+ def ingiza_alama tokeo, maalama, hashi
104
+ herufu_tokeo = tokeo.split ""
105
+ sehemu_tokeo = hashi % @urefu
106
+ sehemu_alama = hashi % maalama.length
107
+ herufu = herufu_tokeo[sehemu_tokeo]
108
+
109
+ if maalama.include? herufu
110
+ herufu_tokeo[@urefu - sehemu_tokeo] = maalama[sehemu_alama]
111
+ else
112
+ herufu_tokeo[sehemu_tokeo] = maalama[sehemu_alama]
113
+ end
114
+
115
+ herufu_tokeo.join
4
116
  end
5
117
 
6
- def self.nyamaza
7
- p "shhhhh"
118
+ def copi_ila_ubao siri
119
+ Clipboard.copy siri
120
+ puts MAELEZO[:siri_copiwa]
8
121
  end
9
122
  end
@@ -0,0 +1,78 @@
1
+ require 'usiri/toleo'
2
+ require 'usiri/mwisho'
3
+
4
+ class ChaguoCLI
5
+ attr_accessor :jina, :siti, :alama, :urefu, :toleo
6
+
7
+ def initialize
8
+ @jina = nil
9
+ @siti = nil
10
+ @alama = nil
11
+ @urefu = nil
12
+ @toleo = nil
13
+ @toleo_usiri = Usiri::TOLEO
14
+ end
15
+
16
+ def fasili_chaguo mfasili
17
+ mfasili.banner = 'usiri [chaguo]'
18
+
19
+ chaguo_jina mfasili
20
+ chaguo_siti mfasili
21
+ chaguo_alama mfasili
22
+ chaguo_urefu mfasili
23
+ chaguo_toleo mfasili
24
+
25
+ mfasili.on_tail("-m", MAELEZO[:msaada]) do
26
+ puts mfasili
27
+ exit
28
+ end
29
+
30
+ mfasili.on_tail("-T", MAELEZO[:toleo_usiri]) do
31
+ puts @toleo_usiri
32
+ exit
33
+ end
34
+ end
35
+
36
+ private
37
+ def chaguo_jina mfasili
38
+ mfasili.on("-j", "--jina JINA", MAELEZO[:jina]) do |jina|
39
+ raise kosa jina if jina.match? CHAGUO_CLI_REGEX
40
+ @jina = jina
41
+ end
42
+ end
43
+
44
+ def chaguo_siti mfasili
45
+ mfasili.on("-s", "--siti SITI", MAELEZO[:siti]) do |siti|
46
+ raise kosa siti if siti.match? CHAGUO_CLI_REGEX
47
+ @siti = siti
48
+ end
49
+ end
50
+
51
+ def chaguo_alama mfasili
52
+ mfasili.on("-a", "--alama [AINA]", AINA_MAALAMA,
53
+ MAELEZO[:alama]) do |alama|
54
+ if AINA_MAALAMA.include? alama
55
+ @alama = alama
56
+ else
57
+ @alama = ALAMA_MSINGI
58
+ end
59
+ end
60
+ end
61
+
62
+ def chaguo_urefu mfasili
63
+ mfasili.on("-u", "--urefu UREFU", UREFU_REGEX, MAELEZO[:urefu]) do |urefu|
64
+ @urefu = urefu.to_i
65
+ end
66
+ end
67
+
68
+ def chaguo_toleo mfasili
69
+ mfasili.on("-t", "--toleo TOLEO", TOLEO_REGEX, MAELEZO[:toleo]) do |toleo|
70
+ @toleo = toleo
71
+ end
72
+ end
73
+
74
+ def kosa jibu
75
+ OptionParser::InvalidArgument.new jibu
76
+ end
77
+
78
+ end
@@ -0,0 +1,52 @@
1
+ require 'optparse'
2
+ require 'usiri/chaguo_cli'
3
+ require 'usiri/muombi'
4
+
5
+ module Msaidizi
6
+ extend self
7
+
8
+ def chambua_chaguo(chaguo_cli)
9
+ chaguo_asili = chambua_chaguo_cli chaguo_cli
10
+ omba_chaguo_kama_hazipo chaguo_asili
11
+ end
12
+
13
+ private
14
+ def chambua_chaguo_cli chaguo_cli
15
+ chaguo_asili = ChaguoCLI.new
16
+
17
+ OptionParser.new do |mfasili|
18
+ chaguo_asili.fasili_chaguo mfasili
19
+
20
+ begin
21
+ mfasili.parse! chaguo_cli
22
+ rescue Exception => kosa
23
+ onyesha_kosa kosa, mfasili
24
+ exit
25
+ end
26
+ end
27
+
28
+ chaguo_asili
29
+ end
30
+
31
+ def onyesha_kosa kosa, mfasili
32
+ makosa = [
33
+ OptionParser::AmbiguousArgument,
34
+ OptionParser::AmbiguousOption,
35
+ OptionParser::InvalidArgument,
36
+ OptionParser::InvalidOption,
37
+ OptionParser::MissingArgument,
38
+ OptionParser::NeedlessArgument
39
+ ]
40
+
41
+ if makosa.include? kosa.class
42
+ puts kosa.message
43
+ puts mfasili
44
+ else
45
+ raise kosa
46
+ end
47
+ end
48
+
49
+ def omba_chaguo_kama_hazipo chaguo_asili
50
+ Muombi.new chaguo_asili
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ require 'usiri/mwisho'
2
+
3
+ module Muhakikisha
4
+ extend self
5
+ def siri s
6
+ not s.empty?
7
+ end
8
+
9
+ def urefu u
10
+ u.match? UREFU_REGEX
11
+ end
12
+
13
+ def toleo t
14
+ t.match? TOLEO_REGEX
15
+ end
16
+ end
@@ -0,0 +1,116 @@
1
+ require 'io/console'
2
+ require "inquirer"
3
+ require "usiri/mwisho"
4
+ require "usiri/muhakikisha"
5
+
6
+ class Muombi
7
+ attr_accessor :jina, :siti, :siri, :alama, :urefu, :toleo
8
+
9
+ def initialize(chaguo_asili)
10
+ @jina = leta_chaguo chaguo_asili, :jina, 'JINA_USIRI'
11
+ @siti = leta_chaguo chaguo_asili, :siti
12
+ @siri = leta_chaguo chaguo_asili, :siri
13
+ @alama = leta_chaguo chaguo_asili, :alama
14
+ @urefu = leta_chaguo(chaguo_asili, :urefu).to_i
15
+ @toleo = leta_chaguo chaguo_asili, :toleo
16
+ end
17
+
18
+ private
19
+ def leta_chaguo chaguo_asili, chaguo, jina_env = nil
20
+ jibu = leta_chaguo_asili chaguo_asili, chaguo
21
+
22
+ if jibu.nil?
23
+ if not jina_env.nil?
24
+ jibu = ENV[jina_env]
25
+ else
26
+ muhakikisha = tengeneza_muhakikisha chaguo
27
+ jibu = omba chaguo
28
+
29
+ if not muhakikisha.nil?
30
+ while not muhakikisha.call jibu
31
+ jibu = omba chaguo, kosa=true
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ jibu
38
+ end
39
+
40
+ def leta_chaguo_asili chaguo_asili, chaguo
41
+ chaguo_asili.method(chaguo).call if chaguo != :siri
42
+ end
43
+
44
+ def omba chaguo, kosa = false
45
+ swala = tengeneza_swala chaguo, kosa
46
+ ombi = tengeneza_ombi chaguo
47
+
48
+ if chaguo == :siri
49
+ return ombi.call(swala).strip
50
+ else
51
+ chaguo_ombi = tengeneza_chaguo_ombi chaguo
52
+
53
+ if chaguo == :alama
54
+ sehemu = ombi.call swala, AINA_MAALAMA, chaguo_ombi
55
+ return AINA_MAALAMA[sehemu]
56
+ else
57
+ return ombi.call(swala, chaguo_ombi).strip
58
+ end
59
+ end
60
+ end
61
+
62
+ def tengeneza_muhakikisha chaguo
63
+ begin
64
+ return Muhakikisha.method chaguo
65
+ rescue NameError
66
+ return nil
67
+ end
68
+ end
69
+
70
+ def tengeneza_swala chaguo, kosa = false
71
+ swala = MAELEZO[chaguo]
72
+
73
+ case chaguo
74
+ when :alama
75
+ swala = "chagua " + swala
76
+ else
77
+ swala = "Ingiza " + swala
78
+ end
79
+
80
+ swala = "#{MAELEZO[:jaribu_tena]} " + swala if kosa
81
+ swala
82
+ end
83
+
84
+ def tengeneza_ombi chaguo
85
+ case chaguo
86
+ when :siri then self.method :omba_siri
87
+ when :alama then Ask.method :list
88
+ else Ask.method :input
89
+ end
90
+ end
91
+
92
+ def tengeneza_chaguo_ombi chaguo
93
+ opts = { response: false }
94
+
95
+ case chaguo
96
+ when :urefu
97
+ opts[:default] = UREFU_MSINGI.to_s
98
+ when :toleo
99
+ opts[:default] = TOLEO_MSINGI.to_s
100
+ end
101
+ opts
102
+ end
103
+
104
+ def omba_siri swala
105
+ # swala = "Ingiza siri ku: "
106
+ # swala = "#{MAELEZO[:jaribu_tena]} " + swala if kosa
107
+ print swala
108
+ ingizo = STDIN.noecho(&:gets).strip
109
+ clear_line
110
+ ingizo
111
+ end
112
+
113
+ def clear_line
114
+ print "\r\e[0K"
115
+ end
116
+ end
@@ -0,0 +1,25 @@
1
+ require "colorize"
2
+
3
+ UREFU_WASTAN_CHINI = 16
4
+ UREFU_WASTAN_JU = 88
5
+ UREFU_MSINGI = 23
6
+ UREFU_REGEX = /^[1-7][6-9]$|^[2-7][0-9]$|^8[0-8]$/
7
+ TOLEO_MSINGI = 1.0
8
+ TOLEO_REGEX = /^-?[\d]+\.?[\d]*$/
9
+ ALAMA_MSINGI = :yoyote
10
+ ALAMA_REGEX = /[\W_]/
11
+ AINA_MAALAMA = [ALAMA_MSINGI, :safi, :bila]
12
+ CHAGUO_CLI_REGEX = /^-[jsautTm]$|^--jina$|^--siti$|^--alama$|^--urefu$|^--toleo$/
13
+ MAELEZO = {
14
+ jina: "jina itayotumwika kutengeneza siri",
15
+ siti: "siti itayotumwika kutengeneza siri",
16
+ siri: "siri ku: ",
17
+ alama: "aina ya alama | moja katita [#{AINA_MAALAMA.join(" ,")}]",
18
+ urefu: "urefu wa siri. msingi: #{UREFU_MSINGI},\
19
+ wastan wa chini: #{UREFU_WASTAN_CHINI}, wastan wa ju: #{UREFU_WASTAN_JU}",
20
+ toleo: "toleo itayotumwika kutengeneza siri. msingi: #{TOLEO_MSINGI}",
21
+ msaada: "Oneysha mesegi hii",
22
+ toleo_usiri: "Oneysha toleo ya programu hii",
23
+ jaribu_tena: "**JARIBU TENA**".black.on_red,
24
+ siri_copiwa: "Siri ime copiwa kwenye ubao".green
25
+ }
@@ -0,0 +1,3 @@
1
+ module Usiri
2
+ TOLEO = "1.0.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "usiri/toleo"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'usiri'
8
+ spec.version = Usiri::TOLEO
9
+ spec.executables << 'usiri'
10
+ spec.date = '2017-10-24'
11
+ spec.summary = "Manega ya maneno ya siri"
12
+ spec.description = "Hii ni programu raisi ya ku hifadhi maneno ya siri"
13
+ spec.authors = ["Itenga"]
14
+ spec.email = 'itenga@protonmail.com'
15
+ spec.files = `git ls-files`.split("\n")
16
+ spec.require_paths = ["lib"]
17
+ spec.homepage = 'https://github.com/msukuma/usiri'
18
+ spec.license = 'MIT'
19
+ end
metadata CHANGED
@@ -1,23 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Itenga Ndaki
7
+ - Itenga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-10-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Hii ni program raisi ya ku hifadhi maneno ya siri
13
+ description: Hii ni programu raisi ya ku hifadhi maneno ya siri
14
14
  email: itenga@protonmail.com
15
- executables: []
15
+ executables:
16
+ - usiri
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - bin/usiri
19
27
  - lib/usiri.rb
20
- homepage: http://rubygems.org/gems/usiri
28
+ - lib/usiri/chaguo_cli.rb
29
+ - lib/usiri/msaidizi.rb
30
+ - lib/usiri/muhakikisha.rb
31
+ - lib/usiri/muombi.rb
32
+ - lib/usiri/mwisho.rb
33
+ - lib/usiri/toleo.rb
34
+ - usiri.gemspec
35
+ homepage: https://github.com/msukuma/usiri
21
36
  licenses:
22
37
  - MIT
23
38
  metadata: {}