code_string 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7993cac0adab3b7e85b3243e3fcacb77f7daee59
4
+ data.tar.gz: 3c196ff7d54e8d474fce4f5cef36ba3d6ffd61aa
5
+ SHA512:
6
+ metadata.gz: eb343e2bd12a0d2da8a00ebb6d14b8b2667342cca028954535357d4521a03bc168a5e01a40e0eca36bbcf5f32571950a83b693d7d20ef4ab03f0724ffdee3f14
7
+ data.tar.gz: d1c9e125d6ebeeb321a34de21fc90908fe63862a86fdb4917b6238ff89eacc0022893cb31bfb197d9d20c9910af815dd3b93c3e35affcffe6f87658009090a65
data/code_string.gemspec CHANGED
@@ -1,23 +1,23 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'code_string'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "code_string"
6
+ spec.name = 'code_string'
8
7
  spec.version = CodeString::VERSION
9
- spec.authors = ["Brice Texier"]
10
- spec.email = ["burisu@oneiros.fr"]
11
- spec.summary = "String to manage codes"
12
- spec.description = "Like AS::SafeBuffer, a way to manage code string safely for code generation"
13
- spec.homepage = ""
14
- spec.license = "MIT"
8
+ spec.authors = ['Brice Texier']
9
+ spec.email = ['burisu@oneiros.fr']
10
+ spec.summary = 'String to manage codes'
11
+ spec.description = 'Like AS::SafeBuffer, a way to manage code string safely for code generation'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
15
14
 
16
15
  spec.files = `git ls-files -z`.split("\x0")
17
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
20
19
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
20
+ spec.add_development_dependency 'bundler', '~> 1.6'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'minitest'
23
23
  end
@@ -0,0 +1,10 @@
1
+ class ::String
2
+ # Convert a String to a Code fragment
3
+ def to_code(language = nil)
4
+ CodeString.new(self, language)
5
+ end
6
+
7
+ def c(language = nil)
8
+ CodeString.new(self, language)
9
+ end
10
+ end
data/lib/code_string.rb CHANGED
@@ -2,8 +2,7 @@
2
2
  # It permits to secure concantenation
3
3
  # Code strings simplifies code displaying
4
4
  class CodeString < String
5
-
6
- VERSION = "0.0.0"
5
+ VERSION = '0.0.1'.freeze
7
6
 
8
7
  class IncompatibleLanguage < StandardError
9
8
  end
@@ -23,10 +22,10 @@ class CodeString < String
23
22
 
24
23
  def +(text)
25
24
  if text.is_a?(CodeString)
26
- if self.language == text.language
25
+ if language == text.language
27
26
  super text
28
27
  else
29
- raise IncompatibleLanguage, "Language #{self.language} is not compatible with language: #{text.language}"
28
+ raise IncompatibleLanguage, "Language #{language} is not compatible with language: #{text.language}"
30
29
  end
31
30
  else
32
31
  super text
@@ -35,10 +34,10 @@ class CodeString < String
35
34
 
36
35
  def <<(text)
37
36
  if text.is_a?(CodeString)
38
- if self.language == text.language
37
+ if language == text.language
39
38
  super text
40
39
  else
41
- raise IncompatibleLanguage, "Language #{self.language} is not compatible with language: #{text.language}"
40
+ raise IncompatibleLanguage, "Language #{language} is not compatible with language: #{text.language}"
42
41
  end
43
42
  else
44
43
  super text.to_s
@@ -46,37 +45,27 @@ class CodeString < String
46
45
  end
47
46
 
48
47
  def to_formatted_s
49
- string, index = "", 1
48
+ string = ''
49
+ index = 1
50
50
  string << "# language: #{language}\n"
51
51
  string << "# encoding: #{encoding}\n"
52
- for line in self.split(/\n/)
53
- string << index.to_s.rjust(4) + ": " + line + "\n"
52
+ for line in split(/\n/)
53
+ string << index.to_s.rjust(4) + ': ' + line + "\n"
54
54
  index += 1
55
55
  end
56
- return string
56
+ string
57
57
  end
58
58
 
59
59
  def inspect
60
- self.to_s
60
+ to_s
61
61
  end
62
62
 
63
63
  def dig(*args)
64
64
  options = args.last.is_a?(Hash) ? args.delete_at(-1) : {}
65
65
  depth = args.shift || options[:depth] || 1
66
- spacer = args.shift || options[:spacer] || " "
67
- return (self.strip.gsub(/^/, spacer * depth) + "\n").c(@language)
66
+ spacer = args.shift || options[:spacer] || ' '
67
+ (strip.gsub(/^/, spacer * depth) + "\n").c(@language)
68
68
  end
69
-
70
69
  end
71
70
 
72
-
73
- class ::String
74
- # Convert a String to a Code fragment
75
- def to_code(language = nil)
76
- CodeString.new(self, language)
77
- end
78
-
79
- def c(language = nil)
80
- CodeString.new(self, language)
81
- end
82
- end
71
+ require 'code_string/core_ext'
data/test/helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Coveralls.wear!
3
3
 
4
4
  require 'bundler/setup'
5
- require 'test/unit'
5
+ require 'minitest/autorun'
6
6
 
7
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
8
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -1,25 +1,19 @@
1
1
  require 'helper'
2
2
 
3
- class TestConcatenation < Test::Unit::TestCase
4
-
3
+ class TestConcatenation < Minitest::Test
5
4
  def test_valid_concatenation
6
- assert_nothing_raised do
7
- "5 + 3\n".c + "5 + 3".c
8
- end
5
+ "5 + 3\n".c + '5 + 3'.c
9
6
 
10
- assert_nothing_raised do
11
- "5 + 3\n".c + "5 + 3".c(:ruby)
12
- end
7
+ "5 + 3\n".c + '5 + 3'.c(:ruby)
13
8
  end
14
9
 
15
10
  def test_invalid_concatenation
16
- assert_raise CodeString::IncompatibleLanguage do
17
- "5 + 3\n".c + "5 + 3".c(:javascript)
11
+ assert_raises CodeString::IncompatibleLanguage do
12
+ "5 + 3\n".c + '5 + 3'.c(:javascript)
18
13
  end
19
14
 
20
- assert_raise CodeString::IncompatibleLanguage do
21
- "5 + 3\n".c(:c) + "5 + 3".c
15
+ assert_raises CodeString::IncompatibleLanguage do
16
+ "5 + 3\n".c(:c) + '5 + 3'.c
22
17
  end
23
18
  end
24
-
25
19
  end
@@ -1,21 +1,15 @@
1
1
  require 'helper'
2
2
 
3
- class TestInstanciation < Test::Unit::TestCase
4
-
3
+ class TestInstanciation < Minitest::Test
5
4
  def test_instanciation_from_string
6
- assert_nothing_raised do
7
- "5 + 3".c
8
- end
5
+ '5 + 3'.c
9
6
  end
10
7
 
11
8
  def test_classical_instanciation
12
9
  cs = nil
13
10
 
14
- assert_nothing_raised do
15
- cs = CodeString.new("5 + 3")
16
- end
11
+ cs = CodeString.new('5 + 3')
17
12
 
18
13
  assert_equal :ruby, cs.language
19
14
  end
20
-
21
15
  end
data/test/test_output.rb CHANGED
@@ -1,23 +1,15 @@
1
1
  require 'helper'
2
2
 
3
- class TestOutput < Test::Unit::TestCase
4
-
3
+ class TestOutput < Minitest::Test
5
4
  def test_inspect_output
6
- assert_nothing_raised do
7
- "5 + 3".c.inspect
8
- end
5
+ '5 + 3'.c.inspect
9
6
  end
10
7
 
11
8
  def test_string_output
12
- assert_nothing_raised do
13
- "5 + 3".c.to_s
14
- end
9
+ '5 + 3'.c.to_s
15
10
  end
16
11
 
17
12
  def test_formatted_string_output
18
- assert_nothing_raised do
19
- "5 + 3\nreturn 0".c.to_formatted_s
20
- end
13
+ "5 + 3\nreturn 0".c.to_formatted_s
21
14
  end
22
-
23
15
  end
metadata CHANGED
@@ -1,46 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
5
- prerelease:
4
+ version: 0.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brice Texier
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-05-04 00:00:00.000000000 Z
11
+ date: 2017-06-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.6'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.6'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  description: Like AS::SafeBuffer, a way to manage code string safely for code generation
@@ -50,13 +59,14 @@ executables: []
50
59
  extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
53
- - .gitignore
62
+ - ".gitignore"
54
63
  - Gemfile
55
64
  - LICENSE.txt
56
65
  - README.rdoc
57
66
  - Rakefile
58
67
  - code_string.gemspec
59
68
  - lib/code_string.rb
69
+ - lib/code_string/core_ext.rb
60
70
  - test/helper.rb
61
71
  - test/test_concatenation.rb
62
72
  - test/test_instanciation.rb
@@ -64,27 +74,26 @@ files:
64
74
  homepage: ''
65
75
  licenses:
66
76
  - MIT
77
+ metadata: {}
67
78
  post_install_message:
68
79
  rdoc_options: []
69
80
  require_paths:
70
81
  - lib
71
82
  required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
83
  requirements:
74
- - - ! '>='
84
+ - - ">="
75
85
  - !ruby/object:Gem::Version
76
86
  version: '0'
77
87
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
88
  requirements:
80
- - - ! '>='
89
+ - - ">="
81
90
  - !ruby/object:Gem::Version
82
91
  version: '0'
83
92
  requirements: []
84
93
  rubyforge_project:
85
- rubygems_version: 1.8.23.2
94
+ rubygems_version: 2.5.2
86
95
  signing_key:
87
- specification_version: 3
96
+ specification_version: 4
88
97
  summary: String to manage codes
89
98
  test_files:
90
99
  - test/helper.rb