therapeutic refactoring - flowcon sf 2014...

301
Therapeutic Refactoring Katrina Owen Jumpstart Lab @kytrinyx

Upload: others

Post on 20-Aug-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Therapeutic Refactoring

Katrina OwenJumpstart Lab

@kytrinyx

Page 2: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File
Page 3: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from Am Adult by Allie Broshhttp://hyperboleandahalf.blogspot.com/2010/03/am-adult.html

Page 4: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Photo: Johanna Owen 2011

Page 5: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from U B Hatin’ by Allie Broshhttp://hyperboleandahalf.blogspot.com/2010/03/u-b-hatin.html

Page 6: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

I❤refactoring

Page 9: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

refactoringis not

rehacktoring

Page 10: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Inspired by true events

A Story

Page 11: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from The Scariest Story by Allie Broshhttp://hyperboleandahalf.blogspot.com/2011/02/scariest-story.html

Page 12: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 13: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from The Scariest Story by Allie Broshhttp://hyperboleandahalf.blogspot.com/2011/02/scariest-story.html

Page 14: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from The Scariest Story by Allie Broshhttp://hyperboleandahalf.blogspot.com/2011/02/scariest-story.html

Page 15: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from The Scariest Story by Allie Broshhttp://hyperboleandahalf.blogspot.com/2011/02/scariest-story.html

Page 16: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 17: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 18: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 19: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 20: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 21: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 22: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 23: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File
Page 24: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

(the first middle)

Tests

Page 25: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService doend

Page 26: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

it "works" do end

end

Page 27: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

subject { XYZService.xyz_filename(stub) }

it "works" do end

end

Page 28: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

subject { XYZService.xyz_filename(stub) }

it "works" do end

end

Page 29: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

subject { XYZService.xyz_filename(stub) }

it "works" do end

end

Page 30: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

subject { XYZService.xyz_filename(stub) }

it "works" do subject.should eq("something") end

end

Page 31: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

subject.should eq "something"

Page 32: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

subject.should eq "whatever"

Page 33: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

subject.should eq "freddy"

Page 34: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

subject.should eq "something"

Page 35: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Failures:

1) XYZService works

Failure/Error: subject.should eq("something")

Stub received unexpected message :publish_on with (no args)

# ./xyz_service.rb:6:in `xyz_filename'

Page 36: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Failures:

1) XYZService works

Failure/Error: subject.should eq("something")

Stub received unexpected message :publish_on with (no args)

# ./xyz_service.rb:6:in `xyz_filename'

Page 37: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Stub received unexpected message

:publish_onwith (no args)

Page 38: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Failures:

1) XYZService works

Failure/Error: subject.should eq("something")

Stub received unexpected message :publish_on with (no args)

# ./xyz_service.rb:6:in `xyz_filename'

Page 39: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

# ./xyz_service.rb:6

Page 40: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 41: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.publish_on.strftime("%d")

Page 42: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.publish_on.strftime("%d")

Page 43: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.publish_on.strftime("%d")

Page 44: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

subject { XYZService.xyz_filename(stub) }

it "works" do end

end

Page 45: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

subject { XYZService.xyz_filename(target) }

it "works" do end

end

Page 46: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

let(:target) do stub(:target) end

subject { XYZService.xyz_filename(target) }

it "works" do subject.should eq("something") end

end

Page 47: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

let(:target) do messages = { } stub(:target, messages) end

subject { XYZService.xyz_filename(target) }

it "works" do subject.should eq("something") end

end

Page 48: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

let(:target) do messages = { :publish_on => ? } stub(:target, messages) end

subject { XYZService.xyz_filename(target) }

it "works" do subject.should eq("something") end

end

Page 49: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe XYZService do

let(:target) do messages = { :publish_on => Date.new(2012, 3, 14) } stub(:target, messages) end

subject { XYZService.xyz_filename(target) }

it "works" do subject.should eq("something") end

end

Page 50: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Stub received unexpected message

:xyz_category_prefixwith (no args)

Page 51: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:xyz_category_prefix => ?,

...

Page 52: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:xyz_category_prefix => 'abc',

...

Page 53: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Stub received unexpected message

:kindwith (no args)

Page 54: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:kind => ?

...

Page 55: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:kind => 'unicorn'

...

Page 56: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Stub received unexpected message

:personal?with (no args)

Page 57: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:personal? => ?

...

Page 58: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:personal? => false

...

Page 59: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Stub received unexpected message

:idwith (no args)

Page 60: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:id => ?

...

Page 61: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:id => 1337

...

Page 62: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Stub received unexpected message

:titlewith (no args)

Page 63: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:title => ?

...

Page 64: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

...

:title => 'magic & superglue'

...

Page 65: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Failures:

1) XYZService works

Failure/Error: subject.should eq("something")

expected: "something"

got: "14abcunicorn_1337_3f4894ca_magicsuper.jpg"

(compared using ==)

# ./xyz_file_spec.rb:18:in `block (2 levels) in <top (required)>

Page 66: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Failures:

1) XYZService works

Failure/Error: subject.should eq("something")

expected: "something"

got: "14abcunicorn_42_3f4894ca_magicsuper.jpg"

(compared using ==)

# ./xyz_file_spec.rb:18:in `block (2 levels) in <top (required)>

#WIN

Page 67: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

let(:target) do messages = { :publish_on => Date.new(2012, 3, 14), :xyz_category_prefix => 'abc', :kind => 'unicorn', :personal? => false, :id => 1337, :title => 'magic & superglue' } stub(:target, messages) end

Page 68: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Failures:

1) XYZService works

Failure/Error: subject.should eq("something")

expected: "something"

got: "14abcunicorn_1337_3f4894ca_magicsuper.jpg"

(compared using ==)

# ./xyz_file_spec.rb:18:in `block (2 levels) in <top (required)>

Page 69: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Failures:

1) XYZService works

Failure/Error: subject.should eq("something")

expected: "something"

got: "14abcunicorn_1337_3f4894ca_magicsuper.jpg"

(compared using ==)

# ./xyz_file_spec.rb:18:in `block (2 levels) in <top (required)>

Page 70: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

14abcunicorn_1337_3f4894ca_magicsuper.jpg

Page 71: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

14abcunicorn_1337_3f4894ca_magicsuper.jpg

Page 72: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

subject.should eq "14abcunicorn_1337_3f4894ca_magicsuper.jpg"

Page 73: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

expected

"14abcunicorn_1337_3f4894ca_magicsuper.jpg"

got

"14abcunicorn_1337_59a2b50d_magicsuper.jpg"

Page 74: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

expected

"14abcunicorn_1337_3f4894ca_magicsuper.jpg"

got

"14abcunicorn_1337_59a2b50d_magicsuper.jpg"

Page 75: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

subject.should eq "14abcunicorn_1337_3f4894ca_magicsuper.jpg"

Page 76: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

subject.should match/14abcunicorn_1337_[0-9a-f]{8}_magicsuper.jpg/

Page 77: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

.

Finished in 0.00073 seconds

1 example, 0 failures

Page 78: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

.

Finished in 0.00073 seconds

1 example, 0 failures#WIN

Page 79: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

Page 80: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

Page 81: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from The Scariest Story by Allie Broshhttp://hyperboleandahalf.blogspot.com/2011/02/scariest-story.html

Page 82: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

Page 83: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.publish_on.strftime("%d")

Page 84: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

:publish_on => Date.new(2012, 3, 14)

Page 85: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

:publish_on => Date.new(2012, 2, 7)

Page 86: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

Page 87: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.kind.gsub("_", "")

Page 88: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

:kind => 'unicorn'

Page 89: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

:kind => 'magic_unicorn'

Page 90: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

Page 91: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.title.gsub(/[^\[a-z\]]/i, '').

downcase

Page 92: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

:title => 'magic & superglue'

Page 93: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

:title => 'I <3 Sparkles!!1!'

Page 94: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from Bycicle by Allie Broshhttp://hyperboleandahalf.blogspot.no/2010/07/bicycle.html

Page 95: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.title.gsub(/[^\[a-z\]]/i, '').

downcase

Page 96: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.title.gsub(/[^\[a-z\]]/i, '').

downcase

Page 97: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "works" { ... } it "leaves square brackets???"

Page 98: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "leaves square brackets???" do target.stub(:title => 'i[sparkle]s') end

Page 99: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

expected

"07abcmagicunicorn_1337_f3b6d325_i[sparkle].jpg"

to match

/07abcmagicunicorn_1337_[0-9a-z]{8}_isparkles.jpg/

Page 100: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "works"{ ... } it "leaves square brackets"{ ... }

Page 101: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

Page 102: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

"_%03d" % (target.age || 0)

if target.personal?

Page 103: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

"_%03d" % (target.age || 0)

if target.personal?

Page 104: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "works" { ... } it "leaves square brackets"{ ... } it "personalizes"

Page 105: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "personalizes" do target.stub(:personal? => true) end

Page 106: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Stub received unexpected message

:agewith (no args)

Page 107: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "personalizes" do target.stub(:personal? => true) target.stub(:age? => 42) end

Page 108: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

"_%03d" % (target.age || 0)

if target.personal?

Page 109: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

"_%03d" % (target.age || 0)

if target.personal?

Page 110: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "works"{ ... } it "leaves square brackets"{ ... } it "personalizes"{ ... } it "handles nil age"

Page 111: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "handles nil age" do target.stub(:personal? => true) target.stub(:age? => nil) end

Page 112: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

Page 113: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

length > 9 ? 9 : length

Page 114: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

:title => 'I <3 Sparkles!!1!'

Page 115: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

:title => 'I <3 SPARKLY Sparkles!!1!'

Page 116: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "works" { ... } it "leaves square brackets" { ... } it "personalizes" { ... } it "handles nil age" { ... } it "handles short titles"

Page 117: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

it "handles short titles" do target.stub(:title => ‘O HAI’) end

Page 118: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

.....

Finished in 0.00386 seconds

5 examples, 0 failures

Page 119: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

.....

Finished in 0.00386 seconds

5 examples, 0 failures#WIN

Page 120: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from This is Why I’ll Never be an Adult by Allie Broshhttp://hyperboleandahalf.blogspot.com/2010/06/this-is-why-ill-never-be-adult.html

Page 121: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Text

Page 122: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

(the second middle)

Refactoring

Page 123: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

replace methodwith method object

Refactoring

Page 124: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFileend

Page 125: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile

def initialize(target) end

end

Page 126: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile

attr_reader :target def initialize(target) @target = target end

end

Page 127: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile

attr_reader :target def initialize(target) @target = target end

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 128: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile

...

def self.xyz_filename(target) ... end

end

Page 129: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile

...

def xyz_filename(target) ... end

end

Page 130: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile

...

def name(target) ... end

end

Page 131: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile

...

def name ... end

end

Page 132: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 133: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) end

end

Page 134: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

require_relative './xyz_file'

module XYZService

def self.xyz_filename(target) end

end

Page 135: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

require_relative './xyz_file'

module XYZService

def self.xyz_filename(target) XYZFile.new end

end

Page 136: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

require_relative './xyz_file'

module XYZService

def self.xyz_filename(target) XYZFile.new end

end

(target)(target)

Page 137: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

require_relative './xyz_file'

module XYZService

def self.xyz_filename(target) XYZFile.new end

end

(target)(target).name

Page 138: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

.....

Finished in 0.00398 seconds

5 examples, 0 failures

Page 139: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

.....

Finished in 0.00398 seconds

5 examples, 0 failures#WIN

Page 140: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 141: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 142: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 143: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 144: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" ... end

end

Page 145: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" ... end

end

Page 146: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" ... end

def truncated_title end

end

Page 147: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" ... end

def truncated_title truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" end

end

Page 148: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name...

def truncated_title truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" end

end

Page 149: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name...

def truncated_title truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" end

end

Page 150: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name...

def truncated_title truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" end

end

Page 151: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name...

def truncated_title truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length truncated_title[0..(truncate_to)] end

end

Page 152: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name...

def truncated_title truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length truncated_title[0..(truncate_to)] end

end

Page 153: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" ... end

def truncated_title...

end

Page 154: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title}" ... end

def truncated_title...

end

Page 155: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title}" ... end

def truncated_title...end

Page 156: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... filename << "_#{truncated_title}" ... end

def truncated_title...

end

Page 157: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def truncated_title...

end

Page 158: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def truncated_title truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length truncated_title[0..(truncate_to)] end

end

Page 159: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def truncated_title truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length truncated_title[0..(truncate_to)] end

end

Page 160: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.title.gsub(/[^\[a-z\]]/i, '').

downcase

Page 161: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.title.gsub(/[^\[a-z\]]/i, '').

downcase

Page 162: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.title.gsub(/[^\[a-z\]]/i, '').

downcase

Page 163: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

target.title.downcasegsub(/[^\[a-z\]]/, '')

Page 164: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

truncated_title[0..(truncate_to)]

Page 165: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

truncated_title[0..(truncate_to)]

Page 166: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

truncated_title[0..truncate_to]

Page 167: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

truncate_to = length > 9 ? 9 : lengthtruncated_title[0..truncate_to]

Page 168: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

truncate_to = length > 9 ? 9 : length

truncated_title[0..9]

Page 169: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

length = truncated_title.lengthtruncate_to = length > 9 ? 9 : length

truncated_title[0..9]

Page 170: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

length = truncated_title.lengthtruncate_to = length > 9 ? 9 : length

truncated_title[0..9]

Page 171: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def truncated_title truncated_title = target.title.downcase.gsub(/[^\[a-z\]]/, '') truncated_title[0..truncate_to] end

end

Page 172: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def truncated_title truncated_title = target.title.downcase.gsub(/[^\[a-z\]]/, '') truncated_title[0..truncate_to] end

end

Page 173: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def truncated_title target.title.downcase. gsub(/[^\[a-z\]]/, '')[0..9] end

end

Page 174: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def truncated_title...

end

Page 175: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def truncated_title...

end

Page 176: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" ... end

def truncated_title...

end

Page 177: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" ... end

def noise end

def truncated_title...

end

Page 178: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" ... end

def noise Digest::SHA1.hexdigest(rand(10000).to_s)[0,8] end

def truncated_title...

end

Page 179: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... filename << "_#{noise}" ... end

def noise Digest::SHA1.hexdigest(rand(10000).to_s)[0,8] end

def truncated_title...

end

Page 180: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def noise...

def truncated_title...

end

Page 181: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def noise...

def truncated_title...

end

Page 182: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def age "%03d" % (target.age || 0) end

def noise...

def truncated_title...

end

Page 183: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def age...

def noise...

def truncated_title...

end

Page 184: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def age...

def noise...

def truncated_title...

end

Page 185: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{publication_day}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def publication_day target.publish_on.strftime("%d") end

def age...

def noise...

def truncated_title...

end

Page 186: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{publication_day}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def publication_day...

def age...

def noise...

def truncated_title...

end

Page 187: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{publication_day}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def publication_day...

def age...

def noise...

def truncated_title...

end

Page 188: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{publication_day}" filename << "#{category}" filename << "#{target.kind.gsub("_", "")}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def category target.xyz_category_prefix end

def publication_day...

def age...

def noise...

def truncated_title...

end

Page 189: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{publication_day}" filename << "#{category}" filename << "#{target.kind.gsub("_", "")}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def publication_day...

def category...

def age...

def noise...

def truncated_title...

end

Page 190: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{publication_day}" filename << "#{category}" filename << "#{kind}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def kind target.kind.gsub("_", "") end

def publication_day...

def category...

def age...

def noise...

def truncated_title...

end

Page 191: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{publication_day}" filename << "#{category}" filename << "#{kind}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def publication_day... def category... def kind... def age... def noise... def truncated_title...

end

Page 192: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "#{publication_day}" filename << "#{category}" filename << "#{kind}" filename << "_#{age}" if target.personal? filename << "_#{target.id.to_s}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" return filename end

def publication_day... def category... def kind... def age... def noise... def truncated_title...

end

Page 193: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename = "#{publication_day}"

Page 194: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename = "#{publication_day}"

Page 195: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename = publication_day

Page 196: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename << "#{category}"

Page 197: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename << category

Page 198: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename << "#{kind}"

Page 199: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename << kind

Page 200: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename << "_#{target.id.to_s}"

Page 201: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

filename << "_#{target.id}"

Page 202: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" filename end ...end

Page 203: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" filename end ...end

Page 204: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" filename end ...end

Page 205: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" filename end ...end

Page 206: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" filename end ...end

Page 207: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" filename end ...end

Page 208: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" filename << ".jpg" filename end ...end

Page 209: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 210: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 211: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 212: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << publication_day filename << category filename << kind filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 213: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... filename << publication_day filename << category filename << kind ... end ...end

Page 214: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... filename << publication_day filename << category filename << kind ... end

def prefix [publication_day, category, kind].join end

...end

Page 215: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name ... filename << prefix ... end

def prefix [publication_day, category, kind].join end

...end

Page 216: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << prefix filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 217: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << prefix filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 218: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 219: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << "_#{age}" if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 220: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = "" filename << prefix filename << age if target.personal? filename << "_#{target.id}" filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 221: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << age if target.personal? filename << target.id filename << "_#{noise}" filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 222: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << age if target.personal? filename << target.id filename << noise filename << "_#{truncated_title}" "#{filename}.jpg" end ...end

Page 223: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << age if target.personal? filename << target.id filename << noise filename << truncated_title "#{filename}.jpg" end ...end

Page 224: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << age if target.personal? filename << target.id filename << noise filename << truncated_title "#{filename.join("_")}.jpg" end ...end

Page 225: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << age if target.personal? filename << target.id filename << noise filename << truncated_title "#{filename.join("_")}.jpg" end

def prefix... def publication_day... def category... def kind... def age... def noise... def truncated_title... ...end

Page 227: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 228: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << age if target.personal? filename << target.id filename << noise filename << truncated_title "#{filename.join("_")}.jpg" end

def prefix... def publication_day... def category... def kind... def age... def noise... def truncated_title... ...end

Page 229: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def prefix [publication_day, category, kind].join end

def publication_day target.publish_on.strftime("%d") end

def category target.xyz_category_prefix end

def kind target.kind.gsub("_", "") end

def age "%03d" % (target.age || 0) end

def noise Digest::SHA1.hexdigest(rand(10000).to_s)[0,8] end

def truncated_title target.title.downcase.gsub(/[^\[a-z\]]/, '')[0..9] end

end

Page 230: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 231: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << age if target.personal? filename << target.id filename << noise filename << truncated_title "#{filename.join("_")}.jpg" end

def prefix... def publication_day... def category... def kind... def age... def noise... def truncated_title... ...end

Page 232: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module XYZService

def self.xyz_filename(target) # File format: # [day of month zero-padded][three-letter prefix] \ # _[kind]_[age_if_kind_personal]_[target.id] \ # _[8 random chars]_[10 first chars of title].jpg filename = "#{target.publish_on.strftime("%d")}" filename << "#{target.xyz_category_prefix}" filename << "#{target.kind.gsub("_", "")}" filename << "_%03d" % (target.age || 0) if target.personal? filename << "_#{target.id.to_s}" filename << "_#{Digest::SHA1.hexdigest(rand(10000).to_s)[0,8]}" truncated_title = target.title.gsub(/[^\[a-z\]]/i, '').downcase length = truncated_title.length truncate_to = length > 9 ? 9 : length filename << "_#{truncated_title[0..(truncate_to)]}" filename << ".jpg" return filename end

end

Page 233: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class XYZFile ... def name filename = [] filename << prefix filename << age if target.personal? filename << target.id filename << noise filename << truncated_title "#{filename.join("_")}.jpg" end

def prefix... def publication_day... def category... def kind... def age... def noise... def truncated_title... ...end

Page 234: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Text

Page 235: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

(the ending)

Codejunk

Page 236: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from Chartjunk by Viveka Weileyhttp://chartjunk.karmanaut.com/?p=8

Page 237: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from Chartjunk by Viveka Weileyhttp://chartjunk.karmanaut.com/test-pattern-retuned/

Page 238: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

(in no particular order)

Top 10

Page 239: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Lousy Comments

#10

Page 240: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

# States the obvious def state_the_obvious "whatever" end

end

Page 241: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

# Takes modulus 100 def say_it_again(number) number % 100 end

end

Page 242: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

# Subtracts def incorrect_comment 1 + 1 end

end

Page 243: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

# add def fuzzy_comment 1 + 1 end

end

Page 244: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

# ad too numbers def bad_comment 1 + 2 end

end

Page 245: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Trailing Whitespace

#9

Page 246: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk def a_method 'Use your words' end end

...................

.................

......

..

..

.

..

Page 247: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Commented-Out Code

#8

Page 248: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def tweaked_logic(wday) # ((7 - wday) % 7) * 1.day (7 - wday) % 7 end

end

Page 249: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def tweaked_logic(wday) if false ((7 - wday) % 7) * 1.day end (7 - wday) % 7 end

end

Page 250: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Needless Parentheses

#7

Page 251: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def spurious_parentheses() junk() end

end

Page 252: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def more_spurious_parentheses (0..(one_method_call)).to_a end

def one_method_call (10 - rand(10)) end

end

Page 253: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Powerless Code

#6

Page 254: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def spurious_arguments [1, 2, 3].join('') end

end

Page 255: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def spurious_arguments [1, 2, 3].join end

end

Page 256: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

class ObjectWrapper

attr_accessor :object def initialize(object) @object = object end

end

Page 257: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def extract(response) if (200..299).include?(response.code.to_i) response.body if response end end

end

Page 258: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def extract(response) if (200..299).include?(response.code.to_i) response.body if response end end

end

Page 259: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def extract(response) if (200..299).include?(response.code.to_i) response.body if response end end

end

Page 260: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Unnecessary Requires

#5

Page 261: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

require 'active_support/all'

# Nothing uses active supportmodule Codejunk ...end

Page 262: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

The booleanest boolean

#4

Page 263: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def truth(code) code == 13 ? true : false end

end

Page 264: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def lie! !true end

end

Page 265: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Too Much Hard Work

#3

Page 266: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def spurious_string_interpolation "#{thing}" end

def thing "a string" end

end

Page 267: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def spurious_stringification "I am #{age.to_s} years old" end

def age rand(25) + 15 end

end

Page 268: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def spurious_transformations [1, 2, 3].map(&:to_s).join end

end

Page 269: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def spurious_complexity s = rand(2) == 0 ? "abcde" : "abc" cutoff = s.length > 4 ? 4 : s.length s[0..cutoff] end

end

Page 270: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def spurious_hard_work s = "I <3 Magic!" s.gsub(/[^a-z]/i, '').downcase end

end

Page 271: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Duplicated Tests

#2

Page 272: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk def add(n1, n2) n1 + n2 endend

describe Codejunk do subject { stub.extend(Codejunk) }

it "adds" do subject.add(1, 1).should eq(2) end

it "adds twin primes" do subject.add(29, 31).should eq(60) end

it "adds big numbers" do subject.add(9238498, 2039238).should eq(11277736) end

it "adds negative numbers" do subject.add(100, -390).should eq(-290) end

end

Page 273: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

describe Codejunk do

subject { stub.extend(Codejunk) }

it "gets rid of spaces" do subject.sanitize(" o m g ").should eq('omg') end

it "gets rid of funky characters" do subject.sanitize("omg^%#=}{?_").should eq('omg') end

it "gets rid of numbers" do subject.sanitize("omg123").should eq('omg') end

it "downcases everything" do subject.sanitize("OMG").should eq('omg') end

end

Page 274: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Combine All The Codejunk

#1

Page 275: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

module Codejunk

def junk # Subtracts s = rand(2) == 0 ? "abcde" : "abc" cutoff = s.length > 4 ? 4 : s.length s = s[0..cutoff] s << "#{spurious_string_interpolation()}" s << "I am #{age.to_s} years old, and " s << "I <3 Magic!".gsub(/[^a-z]/i, '').downcase s << "#{(0..(one_method_call)).map(&:to_s).join('')}" return s end

end

Page 276: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Text

Page 277: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

github.com/kytrinyx /therapeutic-refactoring

Page 278: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Refactoring by Martin Fowler et al.http://www.goodreads.com/book/show/44936.Refactoring

Refactoring, Ruby Edition by Jay Fields et al.http://www.goodreads.com/book/show/11560939-refactoring

Page 279: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Working Effectively With Legacy Code by Michael Feathershttp://www.goodreads.com/book/show/44919.Working_Effectively_with_Legacy_Code

Page 280: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Practical Object-Oriented Design in Ruby by Sandi Metzhttp://www.goodreads.com/book/show/13507787-practical-object-oriented-design-in-ruby

Page 281: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

(the moral)

Therapy

Page 282: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File
Page 283: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

I❤refactoring

Page 284: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Working Memory

Science!

* Beilock & DeCaro, Department of Psychology, University of Chicagohttp://www.ncbi.nlm.nih.gov/pubmed/17983308

Page 285: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Problem-Solving Strategies

Science!

Page 286: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Worry & Panic

Science!

Page 287: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

makes you smarter!

Refactoring

Page 288: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Exobrain

Page 289: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

counteracts panic

Exobrain

Page 290: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

makes you happier!

Refactoring

Page 291: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Fast Tests

Page 292: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

are awesome

Fast Tests

Page 293: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Happiness

Page 294: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

leads to good design

Happiness

Page 295: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from God of Cake by Allie Broshhttp://hyperboleandahalf.blogspot.no/2010/10/god-of-cake.html

Page 296: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

exobrain

Illustration from God of Cake by Allie Broshhttp://hyperboleandahalf.blogspot.no/2010/10/god-of-cake.html

Page 297: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from God of Cake by Allie Broshhttp://hyperboleandahalf.blogspot.no/2010/10/god-of-cake.html

prevents panic

Page 298: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from God of Cake by Allie Broshhttp://hyperboleandahalf.blogspot.no/2010/10/god-of-cake.html

happiness

Page 299: Therapeutic Refactoring - Flowcon SF 2014 Conferenceflowcon.org/.../KatrinaOwen_TherapeuticRefactoring.pdf · 2013. 11. 1. · module XYZService def self.xyz_filename(target) # File

Illustration from God of Cake by Allie Broshhttp://hyperboleandahalf.blogspot.no/2010/10/god-of-cake.html

decoupled code