Last active
December 16, 2015 06:09
-
-
Save austa/5389271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/ruby | |
| class Base | |
| def initialize(isim,uzanti) | |
| base_url = '/home' | |
| @dosya = "#{base_url}/#{isim}.#{uzanti}" | |
| end | |
| def information1 | |
| puts "#{@dosya} dosyasi okunuyor..." | |
| end | |
| def information2 | |
| puts "#{@dosya} dosyasi arsivi basariyla ayiklandi..." | |
| end | |
| end | |
| ######################################## | |
| # ---3--- | |
| #Base sinifindan miras aliyoruz. super ile ustteki sinifin initialize kismindaki degiskenlere atama yapiyoruz. | |
| #yani: | |
| #super(isim,uzanti) | |
| #super ile Base sinifina geciyoruz.sonra isim,uzanti ile Base sınıfımızda initialize fonksiyonunda @dosya ismimizi belirlemis oluyoruz. | |
| #artik tum alt siniflarda dosya ismimizi kullanabiliriz | |
| class Zip < Base | |
| def initialize(isim,uzanti) | |
| super(isim,uzanti) | |
| self.information1 | |
| self.unzip | |
| self.information2 | |
| end | |
| def unzip | |
| system("unzip #{@dosya}") | |
| end | |
| end | |
| class Rar < Base | |
| def initialize(isim,uzanti) | |
| super(isim,uzanti) | |
| self.information1 | |
| self.unrar | |
| self.information2 | |
| end | |
| def unrar | |
| system("unrar x #{@dosya}") | |
| end | |
| end | |
| ################################################## | |
| # --2-- | |
| #Mainde Uzantimizi ayirmistik. Bu fonksiyonumuzda uzantiye gore sinifa yonlendiriyoruz. | |
| class Archive | |
| def initialize(isim,uzanti) | |
| if uzanti == 'zip' | |
| Zip.new(isim,uzanti) | |
| elsif uzanti == 'rar' | |
| Rar.new(isim,uzanti) | |
| else | |
| puts "Dosya Uzantisi Geceersiz" | |
| end | |
| end | |
| end | |
| #################################################### | |
| # --1-- | |
| #ana fonksiyonumuz | |
| #ARG[0] nedir.? ARG[0] ruby'e göre ilk argumani temsil etmektedir. | |
| #Mesela terminalde ls -a -l derken -a ilk argumanimiz olmaktadir. | |
| #programi terminalde kodumuzun bulundugumuz dizinde calistiracagiz. | |
| # ~$ ruby extract.rb deneme.zip | |
| #ARG[0] deneme.zip oldu.split ile noktalara göre dosya adli diziye attik | |
| #isim deneme oldu. Uzantimiz ise zip oldu. Ve sonra bunu Archive adli sinifa gonderdi. | |
| def main | |
| dosya = ARGV[0].split('.') | |
| isim = dosya[0] | |
| uzanti = dosya[1] | |
| Archive.new(isim,uzanti) | |
| end | |
| if __FILE__ == $0 | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment