mme_tools 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7bd4c4ce515497d1b329333dacb5d729f4d3ef4d
4
+ data.tar.gz: 2a4122ea4d0a6121a21bbb9f1a295d7274d24903
5
+ SHA512:
6
+ metadata.gz: f5c4abce54c42e9e281fb9f45c369b71acea9f25741e2d3e56975c2028e63b2489ae027b8ad81c1fe0fcdf06118d5b05178edc0245b81176b8066009b82017a8
7
+ data.tar.gz: b9a317062342d7918653cca4e64ed585171a997849b6740e39908ab2a2c8fc9529308fe71d2895db07e438dd660fcec2e600285b734e5219365866263716c249
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'unicode'
6
+ gem 'iconv'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "bundler"
12
+ gem "jeweler"
13
+ gem "simplecov"
14
+ gem "rr"
15
+ gem 'minitest', ">=5.0.0"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ atomic (1.1.16)
6
+ builder (3.2.2)
7
+ descendants_tracker (0.0.4)
8
+ thread_safe (~> 0.3, >= 0.3.1)
9
+ docile (1.1.3)
10
+ faraday (0.9.0)
11
+ multipart-post (>= 1.2, < 3)
12
+ git (1.2.6)
13
+ github_api (0.11.3)
14
+ addressable (~> 2.3)
15
+ descendants_tracker (~> 0.0.1)
16
+ faraday (~> 0.8, < 0.10)
17
+ hashie (>= 1.2)
18
+ multi_json (>= 1.7.5, < 2.0)
19
+ nokogiri (~> 1.6.0)
20
+ oauth2
21
+ hashie (2.0.5)
22
+ highline (1.6.21)
23
+ iconv (1.0.4)
24
+ jeweler (2.0.1)
25
+ builder
26
+ bundler (>= 1.0)
27
+ git (>= 1.2.5)
28
+ github_api
29
+ highline (>= 1.6.15)
30
+ nokogiri (>= 1.5.10)
31
+ rake
32
+ rdoc
33
+ json (1.8.1)
34
+ jwt (0.1.11)
35
+ multi_json (>= 1.5)
36
+ mini_portile (0.5.3)
37
+ minitest (5.3.2)
38
+ multi_json (1.9.2)
39
+ multi_xml (0.5.5)
40
+ multipart-post (2.0.0)
41
+ nokogiri (1.6.1)
42
+ mini_portile (~> 0.5.0)
43
+ oauth2 (0.9.3)
44
+ faraday (>= 0.8, < 0.10)
45
+ jwt (~> 0.1.8)
46
+ multi_json (~> 1.3)
47
+ multi_xml (~> 0.5)
48
+ rack (~> 1.2)
49
+ rack (1.5.2)
50
+ rake (10.2.2)
51
+ rdoc (4.1.1)
52
+ json (~> 1.4)
53
+ rr (1.1.2)
54
+ simplecov (0.8.2)
55
+ docile (~> 1.1.0)
56
+ multi_json
57
+ simplecov-html (~> 0.8.0)
58
+ simplecov-html (0.8.0)
59
+ thread_safe (0.3.1)
60
+ atomic (>= 1.1.7, < 2)
61
+ unicode (0.4.4.1)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ bundler
68
+ iconv
69
+ jeweler
70
+ minitest (>= 5.0.0)
71
+ rr
72
+ simplecov
73
+ unicode
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Marcel Massana
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,47 @@
1
+ to be updated ...
2
+
3
+ = mme_tools
4
+
5
+ Sparse homeless methods that haven't found their home, ... at present
6
+
7
+ == Usage
8
+
9
+ There are some 'specialized' modules:
10
+
11
+ * MMETools::Concurrent. Some thread save methods thread
12
+ * MMETools::Config. A class that eases configure apps
13
+ * MMETools::Debug. A convenient print_debug method
14
+ * MMETools::Enumerable. Some methods that I use with arrays
15
+ * MMETools::ArgsProc. Methods to process args for methods and initializers.
16
+ * MMETools::Webparse. Methods to cleanup dirty strings from websites
17
+
18
+ To use any of them you can ...
19
+
20
+ require 'rubygems'
21
+ require 'mme_tools/enumerable'
22
+
23
+ or all of them
24
+
25
+ require 'rubygems'
26
+ require 'mmetools'
27
+
28
+ A soon as modules are required, you can use its methods directly as class
29
+ methods like:
30
+
31
+ MMETools::Enumerable.compose(%w(a b), %w(A B), (1..2).to_a)
32
+ # => [["a", "A", 1], ["b", "B", 2]]
33
+
34
+ or include them in your classes to access methods through instances
35
+
36
+ class MyClass
37
+ include MMETools::Enumerable
38
+ end
39
+
40
+ x=MyClass.new
41
+ x.compose(%w(a b), %w(A B), (1..2).to_a)
42
+ # => [["a", "A", 1], ["b", "B", 2]]
43
+
44
+ == Copyright
45
+
46
+ Copyright (c) 2011 Marcel Massana. See LICENSE.txt for
47
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ require './lib/mme_tools/version'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "mme_tools"
19
+ gem.homepage = "http://github.com/syborg/mme_tools"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{various homeless methods}
22
+ gem.description = %Q{generic classes and methods that may be used everywhere}
23
+ gem.email = "xaxaupua@gmail.com"
24
+ gem.authors = ["Marcel Massana"]
25
+ gem.version = MMETools::Version::STRING
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ desc "Code coverage detail"
38
+ task :simplecov do
39
+ ENV['COVERAGE'] = "true"
40
+ Rake::Task['test'].execute
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "mme_tools #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
@@ -0,0 +1,26 @@
1
+ # demo for named_args
2
+ # Marcel Massana 13-Sep-2011
3
+
4
+ #require 'rubygems'
5
+ require '../lib/mme_tools/args_proc'
6
+
7
+ class Dummy
8
+
9
+ include MMETools::ArgsProc
10
+
11
+ def initialize(arg1, arg2, options={})
12
+ # this is an options pattern to check against passed options
13
+ default_opts = {
14
+ :name => 'Marcel',
15
+ :surname => 'Massana',
16
+ :email => nil
17
+ }
18
+ assert_valid_keys options, default_opts
19
+ options.each do |k|
20
+ p k
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ d=Dummy.new 1,2,:name => 'Bartolo', :email => 'j'
@@ -0,0 +1,53 @@
1
+ # demo de utilitzacio de MMETools::Config
2
+ # Marcel Massana 11-Sep-2011
3
+
4
+ require '../lib/mme_tools/config'
5
+ require 'pp'
6
+
7
+ config_file = File.expand_path('tmp/config.yml',File.dirname(__FILE__))
8
+
9
+ config1 = MMETools::Config.new
10
+
11
+ # when creating a config choose any name u want to store values (only one level)
12
+ config1.name = "Joana"
13
+ config1.surname = "Peterson"
14
+ config1.any_name_u_want = "anyname"
15
+ config1.contact = {:emails => ['jo@ana.com', 'j_ana@gmail.com']}
16
+ config1.also = ['Hi There']
17
+
18
+
19
+ # saves config1 in config_file
20
+ config1.dump config_file
21
+
22
+ pp config1.contact.emails
23
+
24
+ config2 = MMETools::Config.new
25
+ config2.load config_file
26
+
27
+ # when accessing an already made config u can access hashes to end level with a
28
+ # simple syntax
29
+ pp config2.class
30
+ pp config2.contact.emails
31
+ pp config2.also
32
+
33
+ # Instantiating a config directly by loading
34
+ config3 = MMETools::Config.load config_file
35
+ pp config3.class
36
+ pp config3.contact.emails
37
+ pp config3.also
38
+
39
+
40
+ config4 = MMETools::Config.new do |c|
41
+ c.param1 = "Hola"
42
+ c.param2 = %w[a b c]
43
+ c.param3 = {:a => {:A=> 'jorl'}, :b => 2}
44
+ end
45
+
46
+ pp config4
47
+ pp config4.to_hash
48
+
49
+ # Merging configs
50
+
51
+ config4.update! config1
52
+
53
+ pp config4
@@ -0,0 +1,67 @@
1
+ # some tiny demos
2
+ # Marcel Massana 2-Sep-2011
3
+
4
+ #require 'rubygems'
5
+ require '../lib/mme_tools/enumerable'
6
+ include MMETools::Enumerable
7
+
8
+ # redefinim each tambe als String com era abans (each ja no es a String des del 1.9)
9
+ class String
10
+ def each(&block)
11
+ split($/).each(&block)
12
+ end
13
+ end
14
+
15
+
16
+ # COMPOSE
17
+ puts "COMPOSE"
18
+
19
+ en1= [1, 2, 3, 4]
20
+ en2= ['a', 'b', 'c', 'd', 'e']
21
+ en3= {:elem1 => "1", :elem2 => "2", :elem3 => "3"}
22
+
23
+ p compose en1.dup, en2.dup, en3.dup
24
+ # => [[1, "a", [:elem1, "1"]], [2, "b", [:elem2, "2"]], [3, "c", [:elem3, "3"]], [4, "d", nil], [nil, "e", nil]]
25
+ p a1=compose(en2.dup, en1.dup) {|a,b| {a.to_sym => b}}
26
+ # => [{:a=>1}, {:b=>2}, {:c=>3}, {:d=>4}, {:e=>nil}]
27
+ p a1.inject({}) {|ac,item| ac.merge item}
28
+ # => {:b=>2, :d=>4, :e=>nil, :c=>3, :a=>1}
29
+ p a1.flatten
30
+ # => [{:a=>1}, {:b=>2}, {:c=>3}, {:d=>4}, {:e=>nil}]
31
+ p a2=compose(en2.dup, en1.dup).flatten
32
+ # => ["a", 1, "b", 2, "c", 3, "d", 4, "e", nil]
33
+ p Hash[*a2]
34
+ # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>nil}
35
+ p a3=compose(en2.dup, en3.dup).flatten
36
+ # => ["a", :elem1, "1", "b", :elem2, "2", "c", :elem3, "3", "d", nil, "e", nil]
37
+
38
+ # CLASSIFY
39
+ puts "CLASSIFY"
40
+
41
+ a1=%w{tantmateix adhuc nogensmenys urgell pocassolta carrincló bajanada casundena Massalcoreig}
42
+ a2 = <<EOF
43
+ petita petunia pestilent
44
+ calikenyo vigoros
45
+ plantunfula casualment rimbombant
46
+ pa amb tomata
47
+ pericó
48
+ EOF
49
+
50
+ p classify(a1) {|el| el[0..0]}
51
+
52
+ p classify(a1) {|el| el.length}
53
+
54
+ p classify(a2) {|el| el.count(" ")+1} # tb: el.count(" ")+1, el.split.size, el.scan(" ").size+1
55
+
56
+ # odd_values and even_values
57
+ p odd_values en1
58
+ # => [2, 4]
59
+ p even_values en1
60
+ # => [1, 3]
61
+ p odd_values en2
62
+ # => [2, 4]
63
+ p even_values en2
64
+ # => [1, 3]
65
+
66
+ # compose what has been decomposed
67
+ p (compose even_values(en2), odd_values(en2)).flatten.compact
@@ -0,0 +1,35 @@
1
+ # print_debug_demo
2
+ # Marcel Massana 2-Sep-2011
3
+ #
4
+ # for those printf driven developers, print_debug outputs the context (the
5
+ # calling stack upto the number of levels required) and pretty prints the
6
+ # following args.
7
+
8
+ #require 'rubygems'
9
+ require '../lib/mme_tools/debug'
10
+
11
+ class A
12
+
13
+ include MMETools::Debug
14
+
15
+ def method_1
16
+ a=File.new __FILE__
17
+ b=Dir.new File.dirname(__FILE__)
18
+ l=__LINE__
19
+ print_debug 1,"These are vars a, b and l in method_1", a,b,l
20
+ self.method_2
21
+ end
22
+
23
+ def method_2
24
+ a=Struct.new(:name, :email).new("Me","me@me.com")
25
+ print_debug 2,"This is var a in method 2", a
26
+ self.method_3
27
+ end
28
+
29
+ def method_3
30
+ print_debug 3,"In method 3, following 3 levels of stack, I'll show you (my)self and (my) class", self, self.class
31
+ end
32
+
33
+ end
34
+
35
+ A.new.method_1
@@ -0,0 +1,22 @@
1
+ # Some dirty tests on MMETools::Webparse
2
+ # Marcel Massana 3-Sep-2011
3
+
4
+ #require 'rubygems'
5
+ require '../lib/mme_tools/webparse'
6
+
7
+ WP = MMETools::Webparse
8
+
9
+ a="ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüý"
10
+ b="AAAAAACEEEEIIIIDNOOOOOxOUUUUYaaaaaaceeeeiiiinoooooouuuuy"
11
+
12
+ dirty_text = "\xC2\xA0Geolog\xC3\xADa,\n \n \t \xC2\xA0 \t Prevenci\xC3\xB3,\tCaçador, Sàtrapa"
13
+
14
+ puts a.chars.map.class, b.split('').class
15
+
16
+ p WP.clear_string dirty_text # => "Geología, Prevenció, Caçador, Sàtrapa"
17
+ p WP.clear_string dirty_text, :encoding => 'ASCII' # => "Geologia, Prevencio, Cacador, Satrapa"
18
+ p WP.asciify dirty_text # => " Geologia,\n \n \t \t Prevencio,\tCacador, Satrapa"
19
+
20
+ # datify
21
+
22
+ puts WP.datify("1/2/10")
@@ -0,0 +1,10 @@
1
+ ---
2
+ :name: Joana
3
+ :surname: Peterson
4
+ :any_name_u_want: anyname
5
+ :contact:
6
+ :emails:
7
+ - jo@ana.com
8
+ - j_ana@gmail.com
9
+ :also:
10
+ - Hi There