Module: Jekyll::DiffFormat

Defined in:
jekyll/_plugins/diff-format.rb

Instance Method Summary collapse

Instance Method Details

#diffFileDate(filename) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'jekyll/_plugins/diff-format.rb', line 58

def diffFileDate(filename)
    # allstudents_old_format_diff.20200820_132518.json
    
     m = filename.match(/.+\.([0-9]{8}_[0-9]{6}).json/)
     parts = m[1].split("_")
     
     year = parts[0].slice(0,4).to_i
     month = parts[0].slice(4,2).to_i
     day = parts[0].slice(6,2).to_i
     
     hour = parts[1].slice(0,2).to_i
     minute = parts[1].slice(2,2).to_i
     second = parts[1].slice(4,2).to_i
     
    "%d-%d-%d %d:%d" % [ year, month, day, hour, minute ]
     
end

#diffFormat(diff, fsuid) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'jekyll/_plugins/diff-format.rb', line 46

def diffFormat(diff,fsuid)
# diff is object mapped to fsuid, doesnot include fsuid
     rows = [];
      # start at top level of record
      flatten_hash("","record",diff,rows,fsuid)
     
#              diff.each do | (key,value) |
#                  flatten_hash("",key,value,rows,fsuid)
#               end         
     return rows
end

#flatten_hash(prekeys, key, value, rows, fsuid) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'jekyll/_plugins/diff-format.rb', line 19

def flatten_hash(prekeys,key,value,rows,fsuid) 

 Jekyll.logger.warn "#{fsuid} prekeys: #{prekeys} key: #{key}"

    if (value.key? "d" and value.key? "old" and value.key? "new")
    
   #     Jekyll.logger.warn "found d"
        
        row_cells = []
        row_cells.push prekeys + key
        row_cells.push value["d"]
        row_cells.push value["old"]
        row_cells.push value["new"]
        rows.push row_cells;
   #     Jekyll.logger.warn "flattened: #{row_cells.join(', ')}"
    else
  #      Jekyll.logger.warn "no d -- so will recurse"
        prekeys = prekeys + key + ".";
        value.each do |subkey, subvalue|
            flatten_hash(prekeys,subkey,subvalue,rows,fsuid);
        end
    end

    return rows

end