Skip to content

Commit 593e3f2

Browse files
committed
fix a bunch of rubymine's style suggestions.
1 parent b7924e8 commit 593e3f2

12 files changed

+39
-39
lines changed

src/fund.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def transactions
8686
transaction_dates.map { |date| row_for date }
8787
end
8888

89-
def price_per_share date
89+
def price_per_share(date)
9090
contribution_for(date) / delta_units_for(date)
9191
end
9292

@@ -113,7 +113,7 @@ def gvis
113113
function drawChart() {
114114
var data = new google.visualization.DataTable();
115115
data.addColumn('date', 'Date');
116-
data.addColumn('number','#{@name}');
116+
data.addColumn('number','#@name');
117117
data.addColumn('string', 'title1');
118118
data.addColumn('string', 'text1');
119119
data.addRows([#{rows}]);

src/interesting_statement_factory.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'investments'
66

77
class InterestingStatementFactory
8-
def read_file filename, statement, interesting = InterestingStatementLines.new
8+
def read_file(filename, statement, interesting = InterestingStatementLines.new)
99
interesting.parse_date filename
1010
statement.items_following(/Ending Balance/) do |lines|
1111
interesting.parse_balances lines[0]
@@ -23,19 +23,19 @@ def read_file filename, statement, interesting = InterestingStatementLines.new
2323
interesting
2424
end
2525

26-
def extract_balances file, fund_data
26+
def extract_balances(file, fund_data)
2727
file.funds.zip(file.balances) do |fund_name, balance|
2828
fund_data.fund(fund_name).write_balance(file.date, balance)
2929
end
3030
end
3131

32-
def extract_contributions file, fund_data
32+
def extract_contributions(file, fund_data)
3333
file.funds.zip(file.contributions) do |fund_name, contribution|
3434
fund_data.fund(fund_name).write_contribution(file.date, contribution)
3535
end
3636
end
3737

38-
def extract_units file, fund_data
38+
def extract_units(file, fund_data)
3939
file.units_funds.zip(file.units).each do |fund_name, units|
4040
fund_data.fund(fund_name).write_units(file.date, units)
4141
end
@@ -51,7 +51,7 @@ def read_statements
5151
end
5252
end
5353

54-
def build_investments interesting_statements
54+
def build_investments(interesting_statements)
5555
fund_data = Investments.new
5656
interesting_statements.each do |file|
5757
extract_balances file, fund_data

src/interesting_statement_lines.rb

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
require 'date'
22
require 'bigdecimal'
33

4-
def convert_money_line money_line
5-
money_line.split(" ").map {|money_string| money_string.gsub(/\$|,/,"").to_f }
4+
def convert_money_line(money_line)
5+
money_line.split(" ").map { |money_string| money_string.gsub(/\$|,/, "").to_f }
66
end
77

88
class InterestingStatementLines
99
attr_reader :balances, :funds, :date, :contributions, :units, :units_funds
1010

11-
def parse_funds funds_line
11+
def parse_funds(funds_line)
1212
@funds = split_funds funds_line
1313
@funds << "TOTAL"
1414
end
1515

16-
def split_funds funds_line
16+
def split_funds(funds_line)
1717
funds_line.strip
1818
funds_line.gsub!("iShares", "XXXiShares")
1919
funds_line.gsub!("Vanguard", "XXXVanguard")
20-
funds_line.gsub!("SPDR","XXXSPDR")
21-
funds_line.sub!("XXX","")
22-
funds_line.split("XXX").map {|f| f.strip }
20+
funds_line.gsub!("SPDR", "XXXSPDR")
21+
funds_line.sub!("XXX", "")
22+
funds_line.split("XXX").map { |f| f.strip }
2323
end
2424

25-
def parse_balances balances_line
25+
def parse_balances(balances_line)
2626
@balances = convert_money_line balances_line
2727
end
2828

29-
def parse_date filename
30-
@date = Date.parse(filename.sub(".txt",""))
29+
def parse_date(filename)
30+
@date = Date.parse(filename.sub(".txt", ""))
3131
end
3232

33-
def parse_contributions contributions_line
33+
def parse_contributions(contributions_line)
3434
@contributions = convert_money_line contributions_line
3535
first = @contributions.size / 3
3636
last = 2 * first - 1
3737
@contributions = @contributions[first..last]
3838
end
3939

40-
def parse_units_funds line
41-
@units_funds = split_funds line.gsub(/(^| )\d\d? /," ")
40+
def parse_units_funds(line)
41+
@units_funds = split_funds line.gsub(/(^| )\d\d? /, " ")
4242
end
4343

44-
def parse_units line
45-
@units = line.split(" ").map {|unit| unit.to_f}
44+
def parse_units(line)
45+
@units = line.split(" ").map { |unit| unit.to_f }
4646
end
4747
end

src/investments.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def fund_names
1212
end
1313

1414
def csv
15-
csv = [(["Date"] + fund_names).join(', ')]
15+
csv = [(%w(Date) + fund_names).join(', ')]
1616
csv += fund("TOTAL").dates.map do |date|
1717
([date] + fund_names.map {|name| fund(name).balance_for(date) }).join(', ')
1818
end

src/units.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
class Units
22
attr_reader :value
33

4-
def initialize value
4+
def initialize(value)
55
@value = (value * 1000).to_i
66
end
77

88
def self.zero
99
@zero ||= Units.new(0)
1010
end
1111

12-
def + addend
12+
def +(addend)
1313
Units.new((value + addend.value) / 1000.0)
1414
end
1515

16-
def - subtrahend
16+
def -(subtrahend)
1717
Units.new((value - subtrahend.value) / 1000.0)
1818
end
1919

20-
def == comparable
20+
def ==(comparable)
2121
value == comparable.value
2222
end
2323

24-
def <=> comparable
24+
def <=>(comparable)
2525
value <=> comparable.value
2626
end
2727

src/util.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Array
2-
def items_following test
3-
index = self.index {|item| test === item }
2+
def items_following(test)
3+
index = self.index { |item| test === item }
44
first = index + 1
55
yield self[first..-1]
66
end

test/fund_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'minitest/autorun'
2-
require 'fund'
2+
require '../src/fund'
33
require 'date'
44
require 'active_support/core_ext'
55

test/interesting_statement_factory_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'minitest/autorun'
2-
require 'interesting_statement_factory'
2+
require '../src/interesting_statement_factory'
33
require 'grasshopper'
44

55
class InterestingStatementFactoryTest < MiniTest::Unit::TestCase
@@ -32,7 +32,7 @@ def test_can_extract_the_right_lines_from_a_statement
3232
end
3333

3434
def test_build_investments
35-
fund_names = ["fund1", "fund2", "TOTAL"]
35+
fund_names = %w(fund1 fund2 TOTAL)
3636
stmt_stub1 = StatementStub.new(fund_names, [99.2, 25.6, 100], [1.1, 2.2, 3.3], [], [], Date.new(2011, 2, 1))
3737
stmt_stub2 = StatementStub.new(fund_names, [12.2, 4.6, 100], [1.4, 2.4, 3.8], [], [], Date.new(2011, 2, 2))
3838

@@ -56,7 +56,7 @@ def test_build_units
5656
class StatementStub
5757
attr_reader :funds, :balances, :date, :contributions, :units_funds, :units
5858

59-
def initialize funds, balances, contributions, units_funds, units, date
59+
def initialize(funds, balances, contributions, units_funds, units, date)
6060
@funds = funds
6161
@balances = balances
6262
@date = date

test/interesting_statement_lines_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'minitest/autorun'
2-
require 'interesting_statement_lines'
2+
require '../src/interesting_statement_lines'
33

44
class InterestingStatementLinesTest < MiniTest::Unit::TestCase
55
def test_parse_funds

test/investments_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'minitest/autorun'
2-
require 'investments'
2+
require '../src/investments'
33
require 'date'
44
require 'active_support/core_ext'
55

test/units_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'minitest/autorun'
2-
require 'units'
2+
require '../src/units'
33

44
class UnitsTest < MiniTest::Unit::TestCase
55
def test_units

test/util_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require 'minitest/autorun'
2-
require 'util'
2+
require '../src/util'
33

44
class UtilTest < MiniTest::Unit::TestCase
55
def test_items_following
6-
data = ["I", "want", "text", "that", "follows", "this", "THESE", "TWO", "NOT", "THIS"]
6+
data = %w(I want text that follows this THESE TWO NOT THIS)
77
result = []
88
data.items_following(/this/) do |items|
99
result << items[0]

0 commit comments

Comments
 (0)