nb_util 0.3.5 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/Gemfile.lock +1 -1
 - data/lib/cli.rb +4 -4
 - data/lib/nb_util/ipynb2tex.rb +23 -20
 - data/lib/nb_util/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c481669cc7f54a88c0397da46a42150cb61b345dcdbc06d1a2a530b964249887
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 63de0433b90627754c066286dfc7e8bb52a2b3b8584cbd82a5e7a71923649910
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d9fe68971aeb2af907acf8474f8361618a7ece511ad0b145839bc58b99933df73fc9d6aecb8694b354e9c76784b861055899c280f429b65ad30a0a3400940231
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: a3a41d88b3979c2463cf40254c71988af2b91c0cc1e40e16dbf3b9f901e49c560b41d1bbb0e964b5c242688c7835ed9b131b778e59f7b1a9ca943592c54d340d
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/cli.rb
    CHANGED
    
    | 
         @@ -36,10 +36,10 @@ module NbUtil 
     | 
|
| 
       36 
36 
     | 
    
         
             
                desc "ipynb2tex [filename]", "convert ipynb to tex" # コマンドの使用例と、概要
         
     | 
| 
       37 
37 
     | 
    
         
             
                def ipynb2tex(argv0) # コマンドはメソッドとして定義する
         
     | 
| 
       38 
38 
     | 
    
         
             
                  NbUtil.ipynb2tex(ARGV[1])
         
     | 
| 
       39 
     | 
    
         
            -
                  NbUtil.revise_lines(ARGV[1])
         
     | 
| 
       40 
     | 
    
         
            -
                  NbUtil.split_files(ARGV[1])
         
     | 
| 
       41 
     | 
    
         
            -
                  NbUtil.replace_figs(ARGV[1])
         
     | 
| 
       42 
     | 
    
         
            -
                  NbUtil.your_informations(ARGV[1])
         
     | 
| 
      
 39 
     | 
    
         
            +
                  #  NbUtil.revise_lines(ARGV[1])
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #  NbUtil.split_files(ARGV[1])
         
     | 
| 
      
 41 
     | 
    
         
            +
                  #  NbUtil.replace_figs(ARGV[1])
         
     | 
| 
      
 42 
     | 
    
         
            +
                  #  NbUtil.your_informations(ARGV[1])
         
     | 
| 
       43 
43 
     | 
    
         
             
                end
         
     | 
| 
       44 
44 
     | 
    
         
             
              end
         
     | 
| 
       45 
45 
     | 
    
         
             
            end
         
     | 
    
        data/lib/nb_util/ipynb2tex.rb
    CHANGED
    
    | 
         @@ -11,21 +11,20 @@ module NbUtil 
     | 
|
| 
       11 
11 
     | 
    
         
             
              def ipynb2tex(target)
         
     | 
| 
       12 
12 
     | 
    
         
             
                loop do
         
     | 
| 
       13 
13 
     | 
    
         
             
                  your_informations(ARGV[1])
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  puts ">上記の情報で実行する場合は「Y」、終了する場合は「N」を入力して下さい。"
         
     | 
| 
      
 14 
     | 
    
         
            +
                  print "Are you ok with it?: "
         
     | 
| 
       16 
15 
     | 
    
         
             
                  input = STDIN.gets.to_s.chomp
         
     | 
| 
       17 
16 
     | 
    
         
             
                  if input == 'Y' || input == 'y'
         
     | 
| 
       18 
17 
     | 
    
         
             
                    location = Open3.capture3("gem environment gemdir")
         
     | 
| 
       19 
18 
     | 
    
         
             
                    versions = Open3.capture3("gem list nb_util")
         
     | 
| 
       20 
19 
     | 
    
         
             
                    latest_version = versions[0].split(",")
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                    p cp_lib_data_thesis_gem = File.join(location[0].chomp, "/gems/#{latest_version[0].chomp.gsub(' (','-').gsub(')','')}/lib/data/thesis")
         
     | 
| 
      
 21 
     | 
    
         
            +
                    p cp_lib_data_pieces_gem = File.join(location[0].chomp, "/gems/#{latest_version[0].chomp.gsub(' (','-').gsub(')','')}/lib/data/pieces")
         
     | 
| 
       23 
22 
     | 
    
         
             
                    cp_lib_data_thesis_bundle = File.join(Dir.pwd, '/lib/data/thesis')
         
     | 
| 
       24 
23 
     | 
    
         
             
                    cp_lib_data_pieces_bundle = File.join(Dir.pwd, '/lib/data/pieces')
         
     | 
| 
       25 
24 
     | 
    
         
             
                    re_fig = /(.+\.jpg)|(.+\.jpeg)|(.+\.png)/
         
     | 
| 
       26 
25 
     | 
    
         | 
| 
       27 
26 
     | 
    
         
             
                    print "\e[32minputfile: \e[0m"
         
     | 
| 
       28 
     | 
    
         
            -
                    target = ARGV[1]
         
     | 
| 
      
 27 
     | 
    
         
            +
                    target = File.expand_path(ARGV[1])
         
     | 
| 
       29 
28 
     | 
    
         
             
                    print "\e[32m#{target}\n\e[0m"
         
     | 
| 
       30 
29 
     | 
    
         
             
                    print "\e[32moutputfile: \e[0m"
         
     | 
| 
       31 
30 
     | 
    
         
             
                    tex_src = target.sub('.ipynb', '.tex')
         
     | 
| 
         @@ -54,13 +53,14 @@ module NbUtil 
     | 
|
| 
       54 
53 
     | 
    
         | 
| 
       55 
54 
     | 
    
         
             
                    mk_xbb(target, re_fig)
         
     | 
| 
       56 
55 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                    if  
     | 
| 
      
 56 
     | 
    
         
            +
                    if Dir.exist?(cp_lib_data_pieces_bundle.to_s)
         
     | 
| 
       58 
57 
     | 
    
         
             
                      FileUtils.cp_r(cp_lib_data_pieces_bundle, target_parent)
         
     | 
| 
       59 
58 
     | 
    
         
             
                      FileUtils.cp_r(cp_lib_data_thesis_bundle, target_parent)
         
     | 
| 
       60 
59 
     | 
    
         
             
                    else
         
     | 
| 
       61 
60 
     | 
    
         
             
                      FileUtils.cp_r(cp_lib_data_pieces_gem, target_parent)
         
     | 
| 
       62 
61 
     | 
    
         
             
                      FileUtils.cp_r(cp_lib_data_thesis_gem, target_parent)
         
     | 
| 
       63 
62 
     | 
    
         
             
                    end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       64 
64 
     | 
    
         
             
            =begin
         
     | 
| 
       65 
65 
     | 
    
         
             
                    if (Open3.capture3("bundle exec exe/nb_util ipynb2tex #{target}")) then
         
     | 
| 
       66 
66 
     | 
    
         
             
                      FileUtils.cp_r(cp_lib_data_pieces_bundle, target_parent)
         
     | 
| 
         @@ -77,10 +77,9 @@ module NbUtil 
     | 
|
| 
       77 
77 
     | 
    
         
             
                    exit
         
     | 
| 
       78 
78 
     | 
    
         
             
                    break
         
     | 
| 
       79 
79 
     | 
    
         
             
                  elsif input == 'N' || input == 'n'
         
     | 
| 
       80 
     | 
    
         
            -
                     
     | 
| 
      
 80 
     | 
    
         
            +
                    target_parent = File.dirname(target)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    FileUtils.rm_r(File.join(target_parent.to_s, '/informations.tex'))
         
     | 
| 
       81 
82 
     | 
    
         
             
                    break
         
     | 
| 
       82 
     | 
    
         
            -
                  else
         
     | 
| 
       83 
     | 
    
         
            -
                    p "「Y」又は「N」を入力して下さい"
         
     | 
| 
       84 
83 
     | 
    
         
             
                  end
         
     | 
| 
       85 
84 
     | 
    
         
             
                end
         
     | 
| 
       86 
85 
     | 
    
         
             
              end
         
     | 
| 
         @@ -149,13 +148,11 @@ module NbUtil 
     | 
|
| 
       149 
148 
     | 
    
         
             
                    caption = lines[i + 1]
         
     | 
| 
       150 
149 
     | 
    
         
             
                    label_name = file_name.to_s.gsub('figs', '').gsub('.png', '').gsub('/', '')
         
     | 
| 
       151 
150 
     | 
    
         
             
                    wrap_figs = <<"EOS"
         
     | 
| 
       152 
     | 
    
         
            -
            \\begin{wrapfigure}{r}{#{size}mm}
         
     | 
| 
       153 
151 
     | 
    
         
             
            \\begin{center}
         
     | 
| 
       154 
     | 
    
         
            -
            \\includegraphics[ 
     | 
| 
       155 
     | 
    
         
            -
            #{caption}
         
     | 
| 
       156 
     | 
    
         
            -
            \\label{fig:#{label_name}}
         
     | 
| 
      
 152 
     | 
    
         
            +
            \\includegraphics[width=#{size}mm]{../../#{file_name}}
         
     | 
| 
       157 
153 
     | 
    
         
             
            \\end{center}
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
      
 154 
     | 
    
         
            +
            #{caption}
         
     | 
| 
      
 155 
     | 
    
         
            +
            \\label{fig:#{label}}
         
     | 
| 
       159 
156 
     | 
    
         
             
            EOS
         
     | 
| 
       160 
157 
     | 
    
         
             
                    # \\vspace{#{top}\\baselineskip}
         
     | 
| 
       161 
158 
     | 
    
         
             
                    # \\vspace{#{bottom}\\baselineskip}
         
     | 
| 
         @@ -187,11 +184,11 @@ EOS 
     | 
|
| 
       187 
184 
     | 
    
         
             
              def your_informations(target)
         
     | 
| 
       188 
185 
     | 
    
         
             
                info = Array.new(3)
         
     | 
| 
       189 
186 
     | 
    
         | 
| 
       190 
     | 
    
         
            -
                print " 
     | 
| 
      
 187 
     | 
    
         
            +
                print "thesis title: "
         
     | 
| 
       191 
188 
     | 
    
         
             
                info[0] = STDIN.gets.to_s.chomp
         
     | 
| 
       192 
     | 
    
         
            -
                print " 
     | 
| 
      
 189 
     | 
    
         
            +
                print "student number(eight-digit): "
         
     | 
| 
       193 
190 
     | 
    
         
             
                info[1] = STDIN.gets.to_s.chomp
         
     | 
| 
       194 
     | 
    
         
            -
                print " 
     | 
| 
      
 191 
     | 
    
         
            +
                print "your name: "
         
     | 
| 
       195 
192 
     | 
    
         
             
                info[2] = STDIN.gets.to_s.chomp
         
     | 
| 
       196 
193 
     | 
    
         | 
| 
       197 
194 
     | 
    
         
             
                target_parent = File.dirname(target)
         
     | 
| 
         @@ -211,17 +208,23 @@ EOS 
     | 
|
| 
       211 
208 
     | 
    
         
             
              end
         
     | 
| 
       212 
209 
     | 
    
         | 
| 
       213 
210 
     | 
    
         
             
              def mk_latex_and_mv_to_latex(target, target_parent)
         
     | 
| 
       214 
     | 
    
         
            -
                mk_latex = File.join(File.dirname(target),'/mk_latex')
         
     | 
| 
       215 
211 
     | 
    
         
             
                mk_latex = FileUtils.mkdir_p(File.join(File.dirname(target),'/mk_latex'))
         
     | 
| 
       216 
     | 
    
         
            -
                 
     | 
| 
      
 212 
     | 
    
         
            +
                if Dir.exist?(File.join(mk_latex[0].to_s, '/pieces'))
         
     | 
| 
      
 213 
     | 
    
         
            +
                  d = Date.today
         
     | 
| 
      
 214 
     | 
    
         
            +
                  old_file = File.join(File.dirname(target),"/old/#{d.year}#{d.month}#{d.day}")
         
     | 
| 
      
 215 
     | 
    
         
            +
                  FileUtils.mkdir_p(old_file)
         
     | 
| 
      
 216 
     | 
    
         
            +
                  FileUtils.cp_r(mk_latex[0], old_file)
         
     | 
| 
      
 217 
     | 
    
         
            +
                  FileUtils.rm_r(mk_latex[0])
         
     | 
| 
      
 218 
     | 
    
         
            +
                end
         
     | 
| 
       217 
219 
     | 
    
         
             
                mk_latex = FileUtils.mkdir_p(File.join(File.dirname(target),'/mk_latex'))
         
     | 
| 
      
 220 
     | 
    
         
            +
             
     | 
| 
       218 
221 
     | 
    
         
             
                #p split_files = FileUtils.mkdir_p(File.join(File.dirname(target),'/mk_latex/split_files'))
         
     | 
| 
       219 
222 
     | 
    
         
             
                split_files = File.join(target_parent, '/split_files')
         
     | 
| 
       220 
223 
     | 
    
         
             
                pieces = File.join(target_parent, '/pieces')
         
     | 
| 
       221 
224 
     | 
    
         
             
                thesis = File.join(target_parent, '/thesis')
         
     | 
| 
       222 
225 
     | 
    
         
             
                latex = File.join(target_parent, '/latex')
         
     | 
| 
       223 
226 
     | 
    
         | 
| 
       224 
     | 
    
         
            -
                FileUtils.mv(split_files, mk_latex[0] 
     | 
| 
      
 227 
     | 
    
         
            +
                FileUtils.mv(split_files, File.join(mk_latex[0], "/split_files"))
         
     | 
| 
       225 
228 
     | 
    
         
             
                FileUtils.mv(pieces, mk_latex[0])
         
     | 
| 
       226 
229 
     | 
    
         
             
                FileUtils.mv(thesis, mk_latex[0])
         
     | 
| 
       227 
230 
     | 
    
         
             
                FileUtils.mv(latex, mk_latex[0])
         
     | 
    
        data/lib/nb_util/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: nb_util
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.8
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Masatoshi Kowaki
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017-12- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-12-21 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |