left-pad 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/left-pad.rb +23 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc4e6922e9961c8ac6eb70b0db4990c9e7061726
4
+ data.tar.gz: 5d12fb048dde49991220a5ae48e60f7be1d0f86a
5
+ SHA512:
6
+ metadata.gz: dea18e5d5f2c1e1857c91d5e6cf5a90a2f854324384b770f4f1b6661ff56e37b32f146010be2defdf63664c9e789089c2668fcf29a25e5174510601118489850
7
+ data.tar.gz: 7959174afa0e4d2f43d7510b7d52278435cb9fcaa0579b500784322b3a29dfdbc496144f76035da76c0b4f2589685eca90c885abd92e7a7abe5cbe52514e00d1
@@ -0,0 +1,23 @@
1
+ class InvalidCharError < StandardError; end
2
+
3
+ class LeftPad
4
+ def LeftPad.leftpad(string, length, character=' ')
5
+ string = string.to_s
6
+ character = character.to_s
7
+ length = length.to_i
8
+
9
+ if character.length != 1
10
+ raise InvalidCharError.new("Invalid character '#{character}'")
11
+ end
12
+
13
+ length = length - string.length
14
+
15
+ if length > 0
16
+ length.times do
17
+ string = "#{character}#{string}"
18
+ end
19
+ end
20
+
21
+ string
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: left-pad
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Somsubhra Bairi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Left pad a string with a character. Inspired by npm left-pad.
14
+ email: mail@somsubhra.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/left-pad.rb
20
+ homepage: http://rubygems.org/gems/left-pad
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Left pad a string with a character
44
+ test_files: []