brdata 0.0.1
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.
- data/CHANGELOG +0 -0
- data/MIT-LICENSE +20 -0
- data/README +0 -0
- data/Rakefile +99 -0
- data/TODO +5 -0
- data/lib/brdata.rb +26 -0
- data/lib/brdata/date_portuguese.rb +41 -0
- data/lib/brdata/time_portuguese.rb +26 -0
- data/lib/brdata/version.rb +9 -0
- data/test/date_test.rb +99 -0
- data/test/test_helper.rb +16 -0
- data/test/time_test.rb +68 -0
- metadata +74 -0
data/CHANGELOG
ADDED
File without changes
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
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
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/contrib/sshpublisher'
|
8
|
+
require File.join(File.dirname(__FILE__), 'lib', 'brdata', 'version')
|
9
|
+
|
10
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
11
|
+
PKG_NAME = 'brdata'
|
12
|
+
PKG_VERSION = BrData::VERSION::STRING + PKG_BUILD
|
13
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
14
|
+
|
15
|
+
RELEASE_NAME = "REL #{PKG_VERSION}"
|
16
|
+
|
17
|
+
RUBY_FORGE_PROJECT = "brdata"
|
18
|
+
RUBY_FORGE_USER = "tapajos"
|
19
|
+
|
20
|
+
desc "Default Task"
|
21
|
+
task :default => [ :test ]
|
22
|
+
|
23
|
+
# Run the unit tests
|
24
|
+
Rake::TestTask.new { |t|
|
25
|
+
t.libs << "test"
|
26
|
+
t.pattern = 'test/*_test.rb'
|
27
|
+
t.verbose = true
|
28
|
+
t.warning = false
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
# Generate the RDoc documentation
|
33
|
+
# Rake::RDocTask.new { |rdoc|
|
34
|
+
# rdoc.rdoc_dir = 'doc'
|
35
|
+
# rdoc.title = "Action Mailer -- Easy email delivery and testing"
|
36
|
+
# rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
37
|
+
# rdoc.options << '--charset' << 'utf-8'
|
38
|
+
# rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
39
|
+
# rdoc.rdoc_files.include('README', 'CHANGELOG')
|
40
|
+
# rdoc.rdoc_files.include('lib/action_mailer.rb')
|
41
|
+
# rdoc.rdoc_files.include('lib/action_mailer/*.rb')
|
42
|
+
# }
|
43
|
+
|
44
|
+
|
45
|
+
# Create compressed packages
|
46
|
+
spec = Gem::Specification.new do |s|
|
47
|
+
s.platform = Gem::Platform::RUBY
|
48
|
+
s.name = PKG_NAME
|
49
|
+
s.summary = "brdata é uma das gems que compoem o Brazilian Rails"
|
50
|
+
s.description = %q{brdata é uma das gems que compoem o Brazilian Rails}
|
51
|
+
s.version = PKG_VERSION
|
52
|
+
|
53
|
+
s.author = "Marcos Tapajós"
|
54
|
+
s.email = "tapajos@gmail.com"
|
55
|
+
s.rubyforge_project = "brdata"
|
56
|
+
s.homepage = "http://www.improveit.com.br/software_livre/brazilian_rails"
|
57
|
+
|
58
|
+
s.add_dependency('activesupport', '>= 1.4.2')
|
59
|
+
|
60
|
+
s.has_rdoc = true
|
61
|
+
s.requirements << 'none'
|
62
|
+
s.require_path = 'lib'
|
63
|
+
# s.autorequire = 'brdata'
|
64
|
+
|
65
|
+
s.files = [ "Rakefile", "README", "CHANGELOG", "TODO", "MIT-LICENSE" ]
|
66
|
+
s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
67
|
+
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
68
|
+
end
|
69
|
+
|
70
|
+
Rake::GemPackageTask.new(spec) do |p|
|
71
|
+
p.gem_spec = spec
|
72
|
+
p.need_tar = true
|
73
|
+
p.need_zip = true
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# desc "Publish the API documentation"
|
78
|
+
# task :pgem => [:package] do
|
79
|
+
# Rake::SshFilePublisher.new("wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# desc "Publish the API documentation"
|
83
|
+
# task :pdoc => [:rdoc] do
|
84
|
+
# Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/am", "doc").upload
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
|
88
|
+
desc "Publish the release files to RubyForge."
|
89
|
+
task :release => [ :package ] do
|
90
|
+
require 'rubyforge'
|
91
|
+
require 'rake/contrib/rubyforgepublisher'
|
92
|
+
|
93
|
+
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
|
94
|
+
|
95
|
+
rubyforge = RubyForge.new
|
96
|
+
rubyforge.configure
|
97
|
+
rubyforge.login
|
98
|
+
rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
|
99
|
+
end
|
data/TODO
ADDED
data/lib/brdata.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'active_support'
|
6
|
+
|
7
|
+
|
8
|
+
%w(date_portuguese
|
9
|
+
time_portuguese
|
10
|
+
version
|
11
|
+
).each {|req| require File.dirname(__FILE__) + "/brdata/#{req}"}
|
12
|
+
|
13
|
+
|
14
|
+
module BrCep
|
15
|
+
end
|
16
|
+
|
17
|
+
old_verbose = $VERBOSE
|
18
|
+
$VERBOSE = nil
|
19
|
+
[Time, Date].each do |clazz|
|
20
|
+
eval "#{clazz}::MONTHNAMES = [nil] + %w(Janeiro Fevereiro Março Abril Maio Junho Julho Agosto Setembro Outubro Novembro Dezembro)"
|
21
|
+
eval "#{clazz}::DAYNAMES = %w(Domingo Segunda-Feira Terça-Feira Quarta-Feira Quinta-Feira Sexta-Feira Sábado)"
|
22
|
+
eval "#{clazz}::ABBR_MONTHNAMES = [nil] + %w(Jan Fev Mar Abr Mai Jun Jul Ago Set Out Nov Dez)"
|
23
|
+
eval "#{clazz}::ABBR_DAYNAMES = %w(Dom Seg Ter Qua Qui Sex Sab)"
|
24
|
+
end
|
25
|
+
|
26
|
+
$VERBOSE = old_verbose
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ActiveSupport::CoreExtensions::String::Conversions
|
2
|
+
# Cria a data no padrao brasileiro e permanece aceitando no formato tradicional.
|
3
|
+
#
|
4
|
+
# Exemplo:
|
5
|
+
# "27/09/2007".to_date
|
6
|
+
def to_date
|
7
|
+
if /(\d{1,2})\W(\d{1,2})\W(\d{4})/ =~ self
|
8
|
+
::Date.new($3.to_i, $2.to_i, $1.to_i)
|
9
|
+
else
|
10
|
+
::Date.new(*ParseDate.parsedate(self)[0..2])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Date
|
16
|
+
|
17
|
+
# Retorna a data no padrao brasileiro
|
18
|
+
#
|
19
|
+
# Exemplo:
|
20
|
+
# data = Date.new(2007, 9, 27)
|
21
|
+
# data.to_s_br ==> "27/09/2007"
|
22
|
+
def to_s_br
|
23
|
+
strftime("%d/%m/%Y")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Valida se uma string eh uma data valida
|
27
|
+
#
|
28
|
+
# Exemplo:
|
29
|
+
# Date.valid?('01/01/2007') ==> true
|
30
|
+
# Date.valid?('32/01/2007') ==> false
|
31
|
+
def self.valid?(date)
|
32
|
+
begin
|
33
|
+
date = date.to_date
|
34
|
+
Date.valid_civil?(date.year, date.month, date.day)
|
35
|
+
rescue
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Time
|
2
|
+
alias :strftime_nolocale :strftime
|
3
|
+
|
4
|
+
# Retorna a hora no padrao brasileiro
|
5
|
+
#
|
6
|
+
# Exemplo:
|
7
|
+
# hora = Time.new
|
8
|
+
# hora.to_s_br ==> "27/09/2007 13:54"
|
9
|
+
def to_s_br
|
10
|
+
self.strftime("%d/%m/%Y %H:%M")
|
11
|
+
end
|
12
|
+
|
13
|
+
# Formata a hora usando nomes de dias e meses em Portugues
|
14
|
+
# Exemplo:
|
15
|
+
# hora = Time.new
|
16
|
+
# hora.strftime("%B") ==> "Janeiro"
|
17
|
+
# http://forum.rubyonbr.org/forums/1/topics/261
|
18
|
+
def strftime(format)
|
19
|
+
format = format.dup
|
20
|
+
format.gsub!(/%a/, Date::ABBR_DAYNAMES[self.wday])
|
21
|
+
format.gsub!(/%A/, Date::DAYNAMES[self.wday])
|
22
|
+
format.gsub!(/%b/, Date::ABBR_MONTHNAMES[self.mon])
|
23
|
+
format.gsub!(/%B/, Date::MONTHNAMES[self.mon])
|
24
|
+
self.strftime_nolocale(format)
|
25
|
+
end
|
26
|
+
end
|
data/test/date_test.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class DateTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# to_date
|
6
|
+
def test_create_date_with_traditional_date_format
|
7
|
+
assert_equal "2007-01-02", "2007/01/02".to_date.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_create_date_with_brazilian_date_format
|
11
|
+
assert_equal "2007-12-13", "13/12/2007".to_date.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_create_date_with_other_brazilian_date_format
|
15
|
+
assert_equal "2007-02-01", "01-02-2007".to_date.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
#to_s
|
20
|
+
def test_date_to_s_with_traditional_format
|
21
|
+
assert_equal "2007-02-01", "01/02/2007".to_date.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
#to_s_br
|
25
|
+
def test_date_to_s_br
|
26
|
+
assert_equal "13/12/2007", "13/12/2007".to_date.to_s_br
|
27
|
+
end
|
28
|
+
|
29
|
+
#valid?
|
30
|
+
def test_valid_when_date_format_is_traditional_and_valid_format_and_valid_civil
|
31
|
+
assert Date.valid?("2007/01/02"), "Should be a valid date"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_valid_when_date_format_is_brazilian_and_valid_format_and_valid_civil
|
35
|
+
assert Date.valid?("13/12/2007"), "Should be a valid date"
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_valid_when_date_format_is_invalid
|
39
|
+
assert !Date.valid?("13/12/200A"), "Should be a invalid date"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_valid_when_date_format_is_brazilian_and_valid_format_and_invalid_civil
|
43
|
+
assert !Date.valid?("00/00/0000"), "Should be a invalid date"
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_month_names
|
47
|
+
assert_equal [nil,
|
48
|
+
"Janeiro",
|
49
|
+
"Fevereiro",
|
50
|
+
"Março",
|
51
|
+
"Abril",
|
52
|
+
"Maio",
|
53
|
+
"Junho",
|
54
|
+
"Julho",
|
55
|
+
"Agosto",
|
56
|
+
"Setembro",
|
57
|
+
"Outubro",
|
58
|
+
"Novembro",
|
59
|
+
"Dezembro"],
|
60
|
+
Date::MONTHNAMES
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_days_names
|
64
|
+
assert_equal ["Domingo",
|
65
|
+
"Segunda-Feira",
|
66
|
+
"Terça-Feira",
|
67
|
+
"Quarta-Feira",
|
68
|
+
"Quinta-Feira",
|
69
|
+
"Sexta-Feira",
|
70
|
+
"Sábado"],
|
71
|
+
Date::DAYNAMES
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_abbr_monthnames
|
75
|
+
assert_equal [nil,
|
76
|
+
"Jan",
|
77
|
+
"Fev",
|
78
|
+
"Mar",
|
79
|
+
"Abr",
|
80
|
+
"Mai",
|
81
|
+
"Jun",
|
82
|
+
"Jul",
|
83
|
+
"Ago",
|
84
|
+
"Set",
|
85
|
+
"Out",
|
86
|
+
"Nov",
|
87
|
+
"Dez"],
|
88
|
+
Date::ABBR_MONTHNAMES
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_abbr_daysnames
|
92
|
+
assert_equal ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"], Date::ABBR_DAYNAMES
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_date_translation_with_strftime
|
96
|
+
assert_equal "Dezembro Dez Sexta-Feira Sex", Date.parse("12/05").strftime("%B %b %A %a")
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/brdata'
|
3
|
+
|
4
|
+
|
5
|
+
def tornar_metodos_publicos(clazz)
|
6
|
+
clazz.class_eval do
|
7
|
+
private_instance_methods.each { |instance_method| public instance_method }
|
8
|
+
private_methods.each { |method| public_class_method method }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def p80 text
|
13
|
+
p '*'*80
|
14
|
+
p text
|
15
|
+
p '*'*80
|
16
|
+
end
|
data/test/time_test.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TimeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
#to_s
|
6
|
+
def test_time_to_s_with_traditional_format
|
7
|
+
assert_equal "Mon Sep 24 16:03:05 UTC 2007", "Mon Sep 24 16:03:05 UTC 2007".to_time.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
#to_s_br
|
11
|
+
def test_time_to_s_br
|
12
|
+
assert_equal "24/09/2007 16:03", "Mon Sep 24 16:03:05 UTC 2007".to_time.to_s_br
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_month_names
|
16
|
+
assert_equal [nil,
|
17
|
+
"Janeiro",
|
18
|
+
"Fevereiro",
|
19
|
+
"Março",
|
20
|
+
"Abril",
|
21
|
+
"Maio",
|
22
|
+
"Junho",
|
23
|
+
"Julho",
|
24
|
+
"Agosto",
|
25
|
+
"Setembro",
|
26
|
+
"Outubro",
|
27
|
+
"Novembro",
|
28
|
+
"Dezembro"],
|
29
|
+
Time::MONTHNAMES
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_days_names
|
33
|
+
assert_equal ["Domingo",
|
34
|
+
"Segunda-Feira",
|
35
|
+
"Terça-Feira",
|
36
|
+
"Quarta-Feira",
|
37
|
+
"Quinta-Feira",
|
38
|
+
"Sexta-Feira",
|
39
|
+
"Sábado"],
|
40
|
+
Time::DAYNAMES
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_abbr_monthnames
|
44
|
+
assert_equal [nil,
|
45
|
+
"Jan",
|
46
|
+
"Fev",
|
47
|
+
"Mar",
|
48
|
+
"Abr",
|
49
|
+
"Mai",
|
50
|
+
"Jun",
|
51
|
+
"Jul",
|
52
|
+
"Ago",
|
53
|
+
"Set",
|
54
|
+
"Out",
|
55
|
+
"Nov",
|
56
|
+
"Dez"],
|
57
|
+
Time::ABBR_MONTHNAMES
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_abbr_daysnames
|
61
|
+
assert_equal ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"], Time::ABBR_DAYNAMES
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_time_translation_with_strftime
|
65
|
+
assert_equal "Dezembro Dez Sexta-Feira Sex", Time.parse("12/05").strftime("%B %b %A %a")
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brdata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Marcos Tapaj\xC3\xB3s"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-22 00:00:00 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.4.2
|
24
|
+
version:
|
25
|
+
description: "brdata \xC3\xA9 uma das gems que compoem o Brazilian Rails"
|
26
|
+
email: tapajos@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- Rakefile
|
35
|
+
- README
|
36
|
+
- CHANGELOG
|
37
|
+
- TODO
|
38
|
+
- MIT-LICENSE
|
39
|
+
- lib/brdata
|
40
|
+
- lib/brdata/date_portuguese.rb
|
41
|
+
- lib/brdata/time_portuguese.rb
|
42
|
+
- lib/brdata/version.rb
|
43
|
+
- lib/brdata.rb
|
44
|
+
- test/date_test.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
- test/time_test.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://www.improveit.com.br/software_livre/brazilian_rails
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements:
|
67
|
+
- none
|
68
|
+
rubyforge_project: brdata
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: "brdata \xC3\xA9 uma das gems que compoem o Brazilian Rails"
|
73
|
+
test_files: []
|
74
|
+
|